帮你实做了一下顺便当练习。给你参考。
import sys
import bs4 as bs
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebPage
import urllib.request
import pandas as pd
class Client(QWebPage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self.on_page_load)
self.mainFrame().load(QUrl(url))
self.app.exec_()
def on_page_load(self):
self.app.quit()
url = 'http://ww2.money-link.com.tw/etf/Ranking2.html'
client_response = Client(url)
source = client_response.mainFrame().toHtml()
soup = bs.BeautifulSoup(source, 'lxml')
js_test = soup.find('table', class_='ETF_table_2 sticky-enabled')
print(js_test.text)
https://i.imgur.com/IlD0trt.jpg
要下载PyQt4
https://i.imgur.com/FcPpN6C.jpg
※ 引述《yeeche (yeech)》之铭言:
: 各位前辈好
: 小弟是python新手 程度应该很low
: 想请教一下用python抓网页的功能
: http://ww2.money-link.com.tw/etf/Ranking2.html
: 我想抓取这个网页的