Python 2.7 使用代理使用BeautifulSoup和Urllib2进行Web抓取

Python 2.7 使用代理使用BeautifulSoup和Urllib2进行Web抓取,python-2.7,beautifulsoup,urllib2,proxies,Python 2.7,Beautifulsoup,Urllib2,Proxies,我试图用代理爬网一个网站,但我得到了错误。我还在学习,所以你的意见将非常有用 这是我的代码: hdr = { "Accept-Language": "en-US,en;q=0.5", "Connection": "keep-alive" } proxies = {'http': 'http://user:pass@us-wa.proxymesh.com:11111', 'https': 'http://user:pass@us-wa.proxymesh.com:1111

我试图用代理爬网一个网站,但我得到了错误。我还在学习,所以你的意见将非常有用

这是我的代码:

hdr = {
    "Accept-Language": "en-US,en;q=0.5",
    "Connection": "keep-alive" 
    }
proxies = {'http': 'http://user:pass@us-wa.proxymesh.com:11111', 'https': 'http://user:pass@us-wa.proxymesh.com:11111'}
try:
    page = BeautifulSoup(urllib2.urlopen(urllib2.Request(urltocrawl_b,headers=hdr,proxies=proxies), timeout=7),'lxml')
except :
    print "-----------------ERROR  ---------------------" 
我得到的错误是:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'proxies'
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:\uuuu init\uuuuuuuuuu()获取了意外的关键字参数“proxies”

谢谢

你得到了哪个错误?看看这个如果我去掉代理,它工作得很好。像这样:hdr={“接受语言”:“en-US,en;q=0.5”,“连接”:“保持活动”}page=BeautifulSoup(urllib2.urlopen(urllib2.Request(urltocrawl\u b,headers=hdr),timeout=7),'lxml')@AlexandreFenyo,我已经添加了错误。谢谢你得到了哪个错误?看看这个如果我去掉代理,它工作得很好。像这样:hdr={“接受语言”:“en-US,en;q=0.5”,“连接”:“保持活动”}page=BeautifulSoup(urllib2.urlopen(urllib2.Request(urltocrawl\u b,headers=hdr),timeout=7),'lxml')@AlexandreFenyo,我已经添加了错误。谢谢