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

时间:2017-03-08 20:47:03

标签: python html beautifulsoup bs4

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

http://prnt.sc/ehltnf

http://prnt.sc/ehltwg

#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())

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

在Chrome开发工具中,您可以检查ajax请求(由Javascript生成)URL。您可以模仿这些请求并获取数据。

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

enter image description here