Re: [問題] 新手學python想抓網頁資料

看板Python作者 (艾爾文)時間6年前 (2019/07/26 10:25), 編輯推噓5(505)
留言10則, 6人參與, 6年前最新討論串2/2 (看更多)
幫你實做了一下順便當練習。給你參考。 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 : 我想抓取這個網頁的 ----- Sent from JPTT on my iPhone -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.186.172 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1564107948.A.683.html

07/26 12:34, 6年前 , 1F
真是太感動了 大感謝 我先好好學習!!
07/26 12:34, 1F

07/26 13:39, 6年前 , 2F
原來還可以這樣用 PyQT!!! 好厲害!!
07/26 13:39, 2F

07/26 13:40, 6年前 , 3F
請問PyQT會像selenium一樣被偵測出是機器人嗎QQ?
07/26 13:40, 3F

07/26 15:02, 6年前 , 4F
ㄟ...我其實整個程式都是照原原po裡有篇YouTube連結裡的
07/26 15:02, 4F

07/26 15:02, 6年前 , 5F
原封不動照抄。只有HTML的Tag和Class換掉而已。在這之前
07/26 15:02, 5F

07/26 15:02, 6年前 , 6F
也沒看過。
07/26 15:02, 6F

07/26 15:39, 6年前 , 7F
pyqt那個只是包裝的瀏覽核心
07/26 15:39, 7F

07/26 15:39, 6年前 , 8F
真正抓的還是BS
07/26 15:39, 8F

07/26 22:21, 6年前 , 9F
怕被偵測機器人可能要學如何偽裝表頭了
07/26 22:21, 9F

07/30 16:23, 6年前 , 10F
太感謝了 感恩分享
07/30 16:23, 10F
文章代碼(AID): #1TEcIiQ3 (Python)
文章代碼(AID): #1TEcIiQ3 (Python)