此page包含Xbox Game Pass上所有可用游戏的列表。我想使用BeautifulSoup检索游戏名称列表
这就是我正在做的:
import requests
from bs4 import BeautifulSoup
page = requests.get('https://www.xbox.com/en-US/xbox-game-pass/games?=pcgames')
if (page.status_code != 200):
print("Unable to load game pass games page")
exit()
soup = BeautifulSoup(page.content, 'html.parser')
soup.find_all('h3', class_='gameDevLink') # returns []
s = soup.prettify()
with open('dump.html', 'w', encoding='utf-8') as f:
f.write(s)
如果我在页面上查看游戏,我会看到如下内容:
每个游戏都包含在一个“a”标记中,其class
设置为gameDevLink
我的问题是soup.find_all('a', class_='gameDevLink')
没有返回命中
如果我将BeautifulSoup生成的html保存到磁盘并搜索gameDevLink
,那么同样没有命中
我不明白为什么我可以在浏览器中看到这些信息,但BeautifulSoup似乎看不到
有关游戏的信息通过Javascript从其他URL加载。您可以使用此脚本对其进行模拟:
印刷品:
相关问题 更多 >
编程相关推荐