我不明白如何从HTML获取数据。硒库

问题描述 投票:0回答:1

解析网站 (wildberry.ru) 时遇到问题。 我无法获取该 DIV 的数据。通过 Xpath 没有帮助。enter image description here

我需要在搜索栏中查询后获取有关文章的信息。

python parsing selenium-webdriver
1个回答
0
投票

如果您可以将 html 保存到文本文件中,您可以使用一些脚本来提取您想要的任何内容

我建议使用美丽汤

pip3 install beautifulsoup4

美丽的汤:

使用示例

from bs4 import BeautifulSoup

# load the HTML in a variable
html_content = "Loaded HTML here"

# parse the HTML
soup = BeautifulSoup(html_content, 'html.parser')

# find all divs elements
all_div = soup.find_all('div')

# Loop over elements
for my_div in all_div:
    try:
        my_div.get("data-link")
    except:
        print("Attribute not found")
© www.soinside.com 2019 - 2024. All rights reserved.