使用python爬虫 taobao 过多请求导致超时

量化分析 2015-02-27 03:13:41
f=open(filename,'wb')
user_agent='Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
header={'User-Agent':user_agent}
req=urllib2.Request(i[0],headers=header)
resp=urllib2.urlopen(req)
data=resp.read()
f.write(data)
f.close()
time.sleep(10)


Traceback (most recent call last):
File "get_taobao_mm.py", line 36, in <module>
sp.get_info()
File "get_taobao_mm.py", line 29, in get_info
resp=urllib2.urlopen(req)
File "C:\Python26\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 383, in open
response = self._open(req, data)
File "C:\Python26\lib\urllib2.py", line 401, in _open
'_open', req)
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 1130, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python26\lib\urllib2.py", line 1105, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or esta

C:\Users\qabuilder\rocky\cache\code>

经常返回以上错误,请问有什么办法可以避免? 按道理已经设置了sleep 10 可以避开ddos了呀
是不是urllib也需要close函数才行????
...全文
302 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
VIP_CQCRE 2015-02-27
  • 打赏
  • 举报
回复
cuiqingcai.com/1076.html

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧