【发布时间】: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