[英]Security error whens scraping ticketing website
I'm trying to scrape a ticketing website for a festival to be notified when a new ticket is available (Note: I am not attempting to illegally buy this ticket through automation). 我试图刮擦票务网站,以便在有新票可用时通知节日(注意:我不是试图通过自动化非法购买此票)。
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import urllib.request
req = urllib.request.Request('http://www.moshtix.com.au/v2/event/splendour-in-the-grass/103360', headers={'User-Agent': 'Mozilla/5.0'})
html = urllib.request.urlopen(req).read()
print(html)
and here is the following error: 这是以下错误:
lib/python3.7/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
I've tried using the answers from related questions with the same error code but all have failed. 我尝试使用相关问题的答案以及相同的错误代码,但都失败了。
Use a more complete user agent, many websites will block bots if the user agent doesn't match a known 'real' user agent. 使用更完整的用户代理,如果用户代理与已知的“真实”用户代理不匹配,许多网站将阻止漫游器。
Try 尝试
headers={'User-Agent': 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.