作者proud (hc)
看板Python
標題[問題] 爬蟲出現問題
時間Tue May 24 12:51:40 2016
想請問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://webptt.com/m.aspx?n=bbs/Python/M.1464065502.A.5CB.html
1F:→ secondDim: google http 50005/24 13:16
有找過才上來問,很多是說設定網際網路選項 http錯誤訊息,但我是用Mac.. 原本抓好
好突然出現這問題@@
※ 編輯: proud (101.15.146.39), 05/24/2016 13:41:32
2F:→ uranusjr: 500 代表 server 自己壞了, 你沒辦法解決05/24 16:59
3F:推 aweimeow: 你試試看把你存取網頁的 UA 塞進去05/24 17:09
4F:→ aweimeow: 之前有碰過因為 UA 不對就故意吐 500 給我的 server05/24 17:09
5F:→ daniel1205: header , cookie 看一下05/24 20:04
請問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
6F:→ aweimeow: 話說你不把 code 貼出來大家要怎麼 debug05/25 13:18
※ 編輯: proud (111.240.30.76), 05/25/2016 21:52:26
寫的不好還請指教,github不太好意思。手機看會失真
※ 編輯: proud (49.214.149.138), 05/25/2016 22:01:35
7F:推 aweimeow: 我剛剛實驗了一下,是 UA 的問題 05/25 22:43
8F:→ aweimeow: 看看這段吧,你能理解問題出在哪05/25 22:48
謝謝aweimeow!
10F:推 kanggy: 謝謝 aweimeow 分享, 學習了 :P05/26 08:54
11F:→ billy0131: 這種防爬蟲的方法到底有什麼用....05/27 11:37
12F:→ s860134: 防君子不防小人阿 最差最差你模仿瀏覽器還是能爬05/27 22:13
13F:→ s860134: 最簡單就是 user-agent, host 比較複雜就 cookie 05/27 22:15
※ 編輯: proud (101.12.147.62), 05/30/2016 19:38:06