代码不在 BS4 上,但可以在 'Inspect Element' 中找到

Code not on BS4, but can be found in 'Inspect Element'

我尝试制作一个网站,使用 Beautiful Soup 4 在 g2a 上搜索游戏价格(作者 class)。问题是,当我查看 HTML 代码时,它清楚地显示了第一个结果的价格(£2.30),但是当我在 Beautiful Soup 4 中搜索 class 时,两者之间没有任何内容相同的 class 标签:

#summoningg2a
r = requests.get('https://www.g2a.com/?search=x')
data = r.text
soup = BeautifulSoup(data, 'html.parser')

#finding prices
prices = soup.find_all("strong", class_="mp-pi-price-min")

print(soup.prettify())

requests 不处理动态页面内容。您最好的选择是使用 Selenium 来驱动浏览器。从那里您可以用 BeautifulSoup 解析 page_source 以获得您正在寻找的结果。

在chrome开发工具中,您可以查看ajax请求(由Javascript发出)URL。您可以模仿该请求并取回数据。

r = requests.get('the ajax requests url')
data = r.text