下面是我用來獲取耐克服裝數據的代碼。在網站上使用python美麗的湯,不斷收到此錯誤:urllib.error.HTTPError:HTTP錯誤403:禁止
import urllib.request
#Base url for website
url = 'http://store.nike.com/us/en_us/pw/mens-clothing/1mdZ7pu?ipp=120'
# A lot of sites don't like the user agents of Python 3, so I specify one here
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
html = urllib.request.urlopen(req).read()
然後錯誤看起來是這樣的:
urllib.error.HTTPError:HTTP錯誤403:禁止
我如何打開和解析這個HTML頁面?
'HTML = urllib.request.urlopen(URL).read()'工作正常 –