Python Beautifulsoup - 通过 Steam 年龄检查
Python Beautiful Soup - Getting past Steam's age check
我正在学习网络抓取,我一直在尝试编写一个从 Steam's website 中提取信息的程序作为练习。
我想编写一个程序,只访问每个排名前 10 的最畅销游戏的页面并提取一些内容,但我的程序在尝试访问 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)
但是没用,我还在年龄查询页面。任何人都可以帮助我,我怎样才能通过它?
我喜欢使用 Selenium Webdriver 进行表单输入,因为它是点击和击键的简单解决方案。您可以在 "Filling out and Submitting Forms" 上查看文档或查看此处的示例。
好的,Steam 似乎使用 cookie 来保存年龄检查结果。它正在使用 birthtime
。
因为我不知道如何使用 urllib
设置 cookie,这里有一个使用 requests
的例子:
import requests
cookies = {'birthtime': '568022401'}
r = requests.get('http://store.steampowered.com/', cookies=cookies)
现在没有年龄检查。
我正在学习网络抓取,我一直在尝试编写一个从 Steam's website 中提取信息的程序作为练习。
我想编写一个程序,只访问每个排名前 10 的最畅销游戏的页面并提取一些内容,但我的程序在尝试访问 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)
但是没用,我还在年龄查询页面。任何人都可以帮助我,我怎样才能通过它?
我喜欢使用 Selenium Webdriver 进行表单输入,因为它是点击和击键的简单解决方案。您可以在 "Filling out and Submitting Forms" 上查看文档或查看此处的示例。
好的,Steam 似乎使用 cookie 来保存年龄检查结果。它正在使用 birthtime
。
因为我不知道如何使用 urllib
设置 cookie,这里有一个使用 requests
的例子:
import requests
cookies = {'birthtime': '568022401'}
r = requests.get('http://store.steampowered.com/', cookies=cookies)
现在没有年龄检查。