def download(source_url):
socket.setdefaulttimeout(10)
agents = ['Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)','Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)','Microsoft Internet Explorer/4.0b1 (Windows 95)','Opera/8.00 (Windows NT 5.1; U; en)']
ree = urllib2.Request(source_url)
ree.add_header('User-Agent',random.choice(agents))
resp = urllib2.urlopen(ree)
htmlSource = resp.read()
return htmlSource
url = "http://myIP/details/?id=4"
result_html = download(url)
它不应该超时......甚至10秒超时..当我尝试从我自己的域下载某些东西时,我怎么会超时?
确认您可以在浏览器中进行连接。尝试从命令提示符下执行“telnet myIP 80”,然后发出'GET/details?id = 4 HTTP/1.1'。怎么了? – jathanism 2010-04-03 01:14:08
'http:// myIP/details /'上有什么服务?如果你使用浏览器去那里,你会看到什么?这个代码中的django在哪里...? – 2010-04-03 01:15:41