[问题] 爬虫出现问题

楼主: proud (hc)   2016-05-24 12:51:40
想请问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()
作者: secondDim ( 祈求备取会上)   2016-05-24 13:16:00
google http 500
作者: uranusjr (←這人是超級笨蛋)   2016-05-24 16:59:00
500 代表 server 自己坏了, 你没办法解决
作者: aweimeow (喵喵喵喵 ヽ( ・∀・)ノ)   2016-05-24 17:09:00
你试试看把你存取网页的 UA 塞进去之前有碰过因为 UA 不对就故意吐 500 给我的 server
作者: daniel1205 (??!!)   2016-05-24 20:04:00
header , cookie 看一下
作者: aweimeow (喵喵喵喵 ヽ( ・∀・)ノ)   2016-05-25 13:18:00
话说你不把 code 贴出来大家要怎么 debug我刚刚实验了一下,是 UA 的问题看看这段吧,你能理解问题出在哪http://pastebin.com/q4ff1tDJ
作者: kanggy ((我还在,只是热情不再))   2016-05-26 08:54:00
谢谢 aweimeow 分享, 学习了 :P
作者: billy0131 (Pluto)   2016-05-27 11:37:00
这种防爬虫的方法到底有什么用....
作者: s860134 (s860134)   2016-05-27 22:13:00
防君子不防小人阿 最差最差你模仿浏览器还是能爬最简单就是 user-agent, host 比较复杂就 cookie

Links booklink

Contact Us: admin [ a t ] ucptt.com