Python 3.5 urllib.request 403 Forbidden Error

為{幸葍}努か 提交于 2019-12-06 09:31:51
宏杰李
import requests
from bs4 import BeautifulSoup


url = "https://www.brightscope.com/ratings"
headers = {'User-Agent':'Mozilla/5.0'}
page = requests.get(url)
soup = BeautifulSoup(page.text, "html.parser")

print(soup.title)

out:

<title>BrightScope Ratings</title>

First, use requests rather than urllib.

Than, add headers to requests, if not, the site will ban your, because the default User-Agent is crawler, which the site do not like.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!