[問題] 爬蟲出現問題

看板Python作者 (hc)時間8年前 (2016/05/24 12:51), 8年前編輯推噓3(3010)
留言13則, 7人參與, 最新討論串1/1
想請問code沒問題下 出現 HTTP Error 500: server error 這樣狀況是什麼問題? 爬的網頁可以開啟 用本地IP去爬也是出現這個error 也排除IP問題 想請問有什麼解決法? code片段如下 抓的是奇摩股票新聞 stockList = [line.rstrip() for line in open('test1.txt')] for count in range(100000000): t1 = time.time() timeCount = 0 for stockNum in stockList: d = feedparser.parse('http://tw.stock.yahoo.com/rss/s/%s' % stockNum) lens = len(d.entries) print lens for newsNum in range(lens): print d.feed.title title = d.entries[newsNum].title.encode('utf-8') print title rTitle = title.replace('/', '.') link = d.entries[newsNum].link req = urllib2.Request(link) print req.__doc__ if not req.__doc__: continue content = urllib2.urlopen(req).read() save = open('./database/%s/%s.news' % (stockNum, rTitle), 'w') save.write(content) save.close() -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.15.146.112 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1464065502.A.5CB.html

05/24 13:16, , 1F
google http 500
05/24 13:16, 1F
有找過才上來問,很多是說設定網際網路選項 http錯誤訊息,但我是用Mac.. 原本抓好 好突然出現這問題@@ ※ 編輯: proud (101.15.146.39), 05/24/2016 13:41:32

05/24 16:59, , 2F
500 代表 server 自己壞了, 你沒辦法解決
05/24 16:59, 2F

05/24 17:09, , 3F
你試試看把你存取網頁的 UA 塞進去
05/24 17:09, 3F

05/24 17:09, , 4F
之前有碰過因為 UA 不對就故意吐 500 給我的 server
05/24 17:09, 4F

05/24 20:04, , 5F
header , cookie 看一下
05/24 20:04, 5F
請問terminal要怎處理? ※ 編輯: proud (111.240.33.176), 05/24/2016 22:17:10 我curl -v 一下 connection : close ※ 編輯: proud (111.240.33.176), 05/24/2016 22:21:03

05/25 13:18, , 6F
話說你不把 code 貼出來大家要怎麼 debug
05/25 13:18, 6F
※ 編輯: proud (111.240.30.76), 05/25/2016 21:52:26 寫的不好還請指教,github不太好意思。手機看會失真 ※ 編輯: proud (49.214.149.138), 05/25/2016 22:01:35

05/25 22:43, , 7F
我剛剛實驗了一下,是 UA 的問題
05/25 22:43, 7F

05/25 22:48, , 8F
看看這段吧,你能理解問題出在哪
05/25 22:48, 8F

05/25 22:48, , 9F
謝謝aweimeow!

05/26 08:54, , 10F
謝謝 aweimeow 分享, 學習了 :P
05/26 08:54, 10F

05/27 11:37, , 11F
這種防爬蟲的方法到底有什麼用....
05/27 11:37, 11F

05/27 22:13, , 12F
防君子不防小人阿 最差最差你模仿瀏覽器還是能爬
05/27 22:13, 12F

05/27 22:15, , 13F
最簡單就是 user-agent, host 比較複雜就 cookie
05/27 22:15, 13F
※ 編輯: proud (101.12.147.62), 05/30/2016 19:38:06
文章代碼(AID): #1NGztUNB (Python)