【问题标题】:Python Beautiful Soup and urllib.request - How to get past Steam age checkPython Beautiful Soup 和 urllib.request - 如何通过 Steam 年龄检查
【发布时间】:2019-09-17 09:51:23
【问题描述】:

我正在尝试制作一个 Steam 解析器,用于从为期一周的交易中获取信息。

但是,有些项目会被年龄检查阻止。我正在使用 urllib.request 和 Beautiful Soup 4 来获取信息,但正如您可能已经猜到的那样,我无法获得 M 级项目。我尝试搜索类似的问题,但没有人告诉我如何使用 urllib.request 来通过年龄检查

只有当项目实际上没有描述时,我才希望测试等于“无描述”

这是我的代码:

import urllib.request

import bs4 as bs

source = urllib.request.urlopen('https://store.steampowered.com/search/?filter=weeklongdeals')
soup = bs.BeautifulSoup(source,'lxml')

searchResultContainer = soup.find('div',{'id':'search_result_container'})
containerHolder = searchResultContainer.findChildren()[1]

links = []
for a in containerHolder.findAll('a', href=True):
    links.append(a['href'])

x = 0
description = []
for link in links:
    source = urllib.request.urlopen(str(link))
    soup = bs.BeautifulSoup(source,'lxml')

    try: 
        test = soup.find('div',{'class':'game_description_snippet'}).get_text().strip()
        description.append(soup.find('div',{'class':'game_description_snippet'}).get_text().strip())
    except:
        test = 'No description'
        description.append('No description')
    finally:
        x += 1
        print(f'{x}: {test}')

【问题讨论】:

    标签: python parsing beautifulsoup steam urllib3


    【解决方案1】:

    我确定年龄选择已保存在 cookie 中,因此您需要保存该 cookie 并将其用于您的会话。

    为了便于使用,我通常建议使用requests,应该可以快速轻松地完成此操作。

    【讨论】:

      猜你喜欢
      • 2016-02-09
      • 2021-03-30
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      相关资源
      最近更新 更多