[問題] 網頁爬蟲 讀不到完整資料

看板Python作者 ( )時間8年前 (2017/01/25 22:33), 8年前編輯推噓0(007)
留言7則, 3人參與, 最新討論串1/1
大家好 我想讀下面網頁的表格 http://pchome.megatime.com.tw/stock/sto3/ock1/sid6505.html 雖然在在document的sid6505.html裡看得到需要的資料 但是程式讀出來卻讀不出來 只能讀到下面幾行 想請教這個問題該如何解決 非常謝謝 <html> <head> </head> <body> <form id='submit_form' name='submit_form' action='http://pchome.megatime.com.tw/stock/sto3/ock1/sid6505.html' method='post'> <input type='hidden' name='is_check' value='1' /> </form> <script type="text/javascript"> document.getElementById('submit_form').submit(); </script> </body> </html> 程式碼: import requests res = requests.get("http://pchome.megatime.com.tw/stock/sto3/ock1/sid6505.html") print (res.text) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.239.185 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1485354796.A.810.html ※ 編輯: ckcy (123.192.239.185), 01/25/2017 22:57:26

01/25 23:38, , 1F
那個網站是用 JS 生成的,只用 requests 會爬不到
01/25 23:38, 1F

01/25 23:39, , 2F
要用 Selenium 或其他類似的工具才爬得到
01/25 23:39, 2F

01/26 00:40, , 3F
不太對喔,是你 header 沒給對,所以他把你擋掉囉~
01/26 00:40, 3F

01/26 00:46, , 4F
測了一下,server 檢查的是 'Referer' 這個 header
01/26 00:46, 4F

01/26 00:48, , 5F
01/26 00:48, 5F

01/26 04:27, , 6F
歹勢,搞錯了 @@
01/26 04:27, 6F

01/26 21:00, , 7F
謝謝s大!! 問題解決了
01/26 21:00, 7F
文章代碼(AID): #1OYBSiWG (Python)
文章代碼(AID): #1OYBSiWG (Python)