我已经成功地使用了urllib2,但是对于这个网站,我突然测试了它并没有工作。我在论坛上看过,并尝试了一些修复程序,它似乎并没有工作。下面是一个解决方案的例子,但不适合我。有人可以帮助我连接到它。HTTP错误403:禁止的urlib2 Python 2.7
,让错误的代码:
from bs4 import BeautifulSoup
import urllib2
proxy_support = urllib2.ProxyHandler({"http":"http://username:[email protected]:port"})
hdr = {'Accept': 'text/html,application/xhtml+xml,*/*'}
url = 'http://www.carnextdoor.com.au/'
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
req=urllib2.Request(url,headers=hdr)
#Here I get the error with and without using the header or going html = urllib2.urlopen(url).read()
html = urllib2.urlopen(req).read()
soup=BeautifulSoup(html,"html5lib")
print soup
您有可能在网站上被阻止 – YOU
? – FancyDolphin
根据回答,这是网站 – YOU