gpt4 book ai didi

python - Beautiful Soup 查找嵌套 div

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:48 24 4
gpt4 key购买 nike

我正在尝试使用 Python->Beautiful Soup 解析看起来像这样的网页

see image

我需要来自

的数据

<div class="p-offer__price-new">199,99 ₽</div>

我尝试了这段代码:

soup = BeautifulSoup(data)
res = soup.findAll("div", {"class": "poffer__price-new"})
print(res)

但是结果是空的 -- []

如何获取这些数据? URL 示例:https://edadeal.ru/moskva/offers/d71b75ff-bfee-4731-95ad-52a24ddea72e?from=%2F

最佳答案

import bs4
from selenium import webdriver

driver = webdriver.Chrome('C:\chromedriver_win32\chromedriver.exe')
driver.get('https://edadeal.ru/moskva/offers/d71b75ff-bfee-4731-95ad-52a24ddea72e?from=%2F')

html = driver.page_source

soup = bs4.BeautifulSoup(html,'html.parser')
res = soup.findAll("div", {"class": "p-offer__price-new"})
print (res[0].text)

driver.close()

关于python - Beautiful Soup 查找嵌套 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53364361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com