简体   繁体   English

如何使用python从硒中提取网页项目列表

[英]How extract list of items from web page with selenium using python

I want to extract information from some site. 我想从某个站点提取信息。 The information that I want to extract is name of Items in list. 我要提取的信息是列表中项目的名称。

Here is example: 这是示例:

<body>
<div class = "_4gt3b">
    <ul class="_539vh _4j13h">
        <li class="_cx1ua">item 1</li>
        <li class="_cx1ua">item 2</li>
        <li class="_cx1ua">item 3</li>
        <li class="_cx1ua">item 4</li>
        <li class="_cx1ua">item 5</li>
    </ul>
</div>

I want extract "item 1,item 2,item 3,..." also I want consider class names "_4gt3b",""_539vh _4j13h","_cx1ua" because It is key to redirect the list of Items. 我想提取“项目1,项目2,项目3,...”,也要考虑类名“ _4gt3b”,“ _ 539vh _4j13h”,“ _ cx1ua”,因为这是重定向项目列表的关键。

I use this code: 我使用以下代码:

WebElement = driver.find_elements_by_css_selector("._4gt3b._539vh._cx1ua")

But return: 但是返回:

>>> WebElement
[]

What is problem(s)? 什么是问题?

您需要空格: $('._4gt3b ._539vh ._cx1ua')

您可以使用此直接获取li的列表

elements = driver.find_elements_by_xpath("/li[@class='_cx1ua']")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python Selenium 从网页中提取页码 - Extract Page number from a web page using Python Selenium 使用CSS选择器从网页提取数据-Selenium Python - Extract data from web page using CSS selector - Selenium Python 如何使用 selenium python 和不同等级的页面从带有滚动的 web 页面中提取所有数据? - how to extract all data from a web page with a scroll using selenium python and different rank pages? 如何从 web whatsapp 中提取此信息; 使用 python 和 selenium - How can extract this information from web whatsapp; using python and selenium 如何从网页的下拉列表中提取数据并使用python在excel中打印 - How to extract data from dropdown list on a web page and print in excel using python 如何使用Selenium和Python遍历项目列表并提取特定部分 - How can I iterate through a list of items and extract a specific part using Selenium and Python 使用xpath-selenium-python从网页中提取文本/数字 - To Extract text / number from web page using xpath-selenium-python 如何使用Selenium python只废弃网页中的电子邮件? - How To Scrap only emails from web page using selenium python? 如何在 Python 中使用 Selenium 从网页中获取数据? - How to get data from a web-page using Selenium in Python? 如何使用python从网页中提取输入元素的值? - How to extract the value of an input element from a web page using python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM