作者hazton (hazton)
看板Python
标题Re: [问题] 抓资料被档@@
时间Sat Sep 26 03:40:11 2009
http://planet.python.org.tw/planet/user/4/tag/python/
我在上面这个网站有找到大概想要的东西
不过直接执行却会出现下面这个讯息:
<addinfourl at 60282000 whose fp = <socket._fileobject object at 0x039023F0>>
程式码如下:
# -*- coding: utf-8 -*-
import urllib
import urllib2
def GetURLContent(url):
req=urllib2.Request(url)
#req.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1;
en-US; rv:1.6) Gecko/20040113')
req.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1;
zh-TW; rv:1.9.0.11) Gecko/2009060215')
req.add_header('Referer','
http://tw.yahoo.com/')
return urllib2.urlopen(req)
data = GetURLContent("
http://tw.yahoo.com/")
print data
有人知道上面的错误讯息代表什麽意思呢?该如何解决?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.142.78
1F:推 buganini:这不是错误讯息 请把WretchGrabPhoto.py看完 09/26 05:07
2F:→ hazton:哦哦,原来是没加.read()阿!现在可以跑了~感谢! 09/26 17:33
3F:→ hazton:不过看来还是无法突破yahoo的门,看来还是要另外想办法噜 09/26 17:42
4F:推 Lucemia:cookie 与host可能有检查 09/28 04:04
5F:→ hazton:所以host用程式是没办法改噜@@? 09/28 11:18
6F:推 buganini:host cookie都是header的一部分 自己查好格式塞进去即可 10/15 00:00