【问题标题】:Python Beautiful Soup - Getting past Steam's age checkPython Beautiful Soup - 通过 Steam 的年龄检查
【发布时间】:2016-02-09 18:17:09
【问题描述】:

我正在学习网络抓取,我一直在尝试编写一个从Steam's website 提取信息的程序作为练习。

我想编写一个程序,只访问每个最畅销游戏的页面并提取一些内容,但是当我的程序尝试访问 M 级游戏时,它只是被重定向到年龄检查页面。

我的程序看起来像这样:

front_page = urlopen('http://store.steampowered.com/').read()
bs = BeautifulSoup(front_page, 'html.parser')
top_sellers = bs.select('#tab_topsellers_content a.tab_item_overlay')

for item in top_sellers:
    game_page = urlopen(item.get('href'))
    bs = BeautifulSoup(game_page.read(), 'html.parser')
    #Now I'm on the age check page :(

我不知道如何通过年龄检查,我尝试通过向其发送 POST 请求来填写年龄检查,如下所示:

post_params = urlencode({'ageDay': '1', 'ageMonth': 'January', 'ageYear': '1988', 'snr': '1_agecheck_agecheck__age-gate'}).encode('utf-8')
page = urlopen(agecheckurl, post_params)

但它不起作用,我还在年龄检查页面上。任何人都可以在这里帮助我,我该如何克服它?

【问题讨论】:

    标签: python python-3.x web-scraping beautifulsoup python-3.5


    【解决方案1】:

    我喜欢使用 Selenium Webdriver 进行表单输入,因为它是点击和击键的简单解决方案。您可以在“填写和提交表格”中查看文档或查看示例。

    https://automatetheboringstuff.com/chapter11/

    【讨论】:

      【解决方案2】:

      好的,Steam 似乎使用 cookie 来保存年龄检查结果。它正在使用birthtime

      由于我不知道如何设置cookie使用urllib,这里是一个使用requests的例子:

      import requests
      cookies = {'birthtime': '568022401'}
      r = requests.get('http://store.steampowered.com/', cookies=cookies)
      

      现在没有年龄检查了。

      【讨论】:

      • 谢谢。但是,对于某些游戏(例如 PST: EE),有一个额外的确认屏幕。为了解决这个问题,这是我的 cookie:cookies = { 'birthtime': '283993201', 'mature_content': '1' }.
      猜你喜欢
      • 2019-09-17
      • 2021-03-30
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      相关资源
      最近更新 更多