python - Python Beautiful Soup 和 urllib.request - 如何通过 Steam 年龄检查
问题描述
我正在尝试制作一个从为期一周的交易中获取信息的 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}')
解决方案
我确定年龄选择保存在 cookie 中,因此您需要保存该 cookie 并将其用于您的会话。
我通常会建议使用请求以方便使用,应该让它快速而轻松。
推荐阅读
- flutter - 一段时间后,我想用android_alarm_manager插件在后台关闭audio_service
- python - 错误:UnicodeDecodeError:“charmap”编解码器无法解码位置 715 中的字节 0x8d:字符映射到
- python - 如何在 Python 中更改日期的格式?
- java - Jacoco 抱怨不太可能缺少分支覆盖
- python - exorcism.io 中的 pangram 问题,python 跟踪,为什么我的解决方案不起作用?
- angular - 错误类型错误:i.createShadowRoot 不是 Angular Web 组件上的函数?
- java - 我们可以在java的扩展抽象类中创建新的抽象方法吗
- java - 单击下拉菜单中的项目后更改 RecyclerView 内容
- programming-languages - Coursera 编程语言 hw2
- ios - 'NSInvalidArgumentException',原因:'+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]:'无法识别的选择器发送到类'