【问题标题】:Security error whens scraping ticketing website抓取票务网站时出现安全错误
【发布时间】:2018-07-07 01:22:50
【问题描述】:

我正在尝试抓取一个票务网站,以便在有新票可用时收到通知(注意:我不是试图通过自动化非法购买这张票)。

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)

这是以下错误:

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

我已经尝试使用相关问题的答案,错误代码相同,但都失败了。

【问题讨论】:

  • 当您将 curl 与该用户代理一起使用时,您会得到相同的结果吗?
  • 没试过,不知道怎么样..

标签: python security beautifulsoup http-status-code-403


【解决方案1】:

使用更完整的用户代理,如果用户代理与已知的“真实”用户代理不匹配,许多网站会阻止机器人。

试试

 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'}

【讨论】:

  • 很高兴听到!选择我的答案旁边的绿色复选标记以标记您的问题已解决。
猜你喜欢
  • 2020-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-03
  • 1970-01-01
相关资源
最近更新 更多