Jus*_*guy 2 python beautifulsoup web-scraping python-3.x python-3.5
我正在学习网络抓取,我一直在努力编写一个程序,从Steam的网站上提取信息作为练习.
我想编写一个程序,只访问每个前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 :(
Run Code Online (Sandbox Code Playgroud)
我不知道如何通过年龄检查,我已经尝试通过发送POST请求来填写年龄检查,如下所示:
post_params = urlencode({'ageDay': '1', 'ageMonth': 'January', 'ageYear': '1988', 'snr': '1_agecheck_agecheck__age-gate'}).encode('utf-8')
page = urlopen(agecheckurl, post_params)
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我仍然在年龄检查页面.任何可以帮助我的人,我怎么能超越它?
好吧,似乎Steam使用cookie来保存年龄检查结果.它正在使用birthtime.
由于我不知道如何设置cookie使用urllib,这里有一个例子使用requests:
import requests
cookies = {'birthtime': '568022401'}
r = requests.get('http://store.steampowered.com/', cookies=cookies)
Run Code Online (Sandbox Code Playgroud)
现在没有年龄检查.
| 归档时间: |
|
| 查看次数: |
774 次 |
| 最近记录: |