连接服务器次数问题 python 新手提问

scrapyshendamrwang 2010-11-04 11:38:55

import os,sys,datetime
import httplib,urllib,re
from sgmllib import SGMLParser
import types
import time
class Html2txt(SGMLParser):
def reset(self):
self.text=''
self.inbody=True
SGMLParser.reset(self)
def handle_data(self,text):
if self.inbody:
self.text+=text
def start_head(self,text):
self.inbody=False
def end_head(self):
self.inbody=True


parser=Html2txt()

for i in range(1,8000):
parser.feed(urllib.urlopen("http://baike.baidu.com/view/%s.html"%i).read())
parser.close()
#print parser.text.strip()
f=open('百度百科1.txt','w')
f.write(parser.text.strip())
for i in ('900','1800','2700',3600',4500','5400','6300','7200'):

time.sleep(40)
f.close()
我 设置睡眠了啊 为什么程序运行一段时间后说Http协议错误啊
...全文
64 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
gavinma 2010-11-04
  • 打赏
  • 举报
回复
应该是超时了吧,保留一下cookie看看

37,738

社区成员

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

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