【发布时间】:2016-06-20 10:47:49
【问题描述】:
我已经成功地能够使用 urllib2,但是对于这个网站,我突然测试它不起作用。我已经在论坛上查看并尝试了一些修复程序,但它似乎不起作用。下面是一种解决方法的示例,但对我不起作用。有人可以帮助我连接到它。
给出错误的代码:
from bs4 import BeautifulSoup
import urllib2
proxy_support = urllib2.ProxyHandler({"http":"http://username:password@ip: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
【问题讨论】:
-
你有可能被屏蔽了
-
按回答是网站