【发布时间】:2019-05-31 18:52:21
【问题描述】:
我想用 python 3.7 写一个脚本。但首先我必须刮它。 我在连接和从非禁止网站获取数据方面没有问题,但如果该网站被禁止,它将无法正常工作。
如果我使用 VPN 服务,我可以使用 Chrome 浏览器进入这些“被禁止”的网站。
我尝试在 pycharm 中设置代理,但失败了。我只是一直出错。 解决这个问题最简单免费的方法是什么?
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup as soup
req = Request('https://www.SOMEBANNEDSITE.com/', headers={'User-Agent': 'Mozilla/5.0'}) # that web site is blocked in my country
webpage = urlopen(req).read() # code stops running at this line because it can't connect to the site.
page_soup = soup(webpage, "html.parser")
【问题讨论】:
标签: python web-scraping proxy scripting vpn