幫你實做了一下順便當練習。給你參考。
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
: 我想抓取這個網頁的