无法使用Xpath定位元素

2024-10-01 22:39:21 发布

您现在位置:Python中文网/ 问答频道 /正文

这里是交易,我有一些sinopse采取了从IMDB网站,但sinopse元素是在一个盒子里没有任何跟踪(如下图),我是这样尝试的,但我不知道如何提取文本,获得_属性或类似的东西。你知道吗

这就是工作版本

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('http://www.imdb.com/title/tt2731500/')

alo = driver.find_element(By.XPATH, '//div[@itemprop="description"]').text
print(alo)

The image of the HTML


Tags: from文本import元素by属性网站driver
1条回答
网友
1楼 · 发布于 2024-10-01 22:39:21

1)将html保存到磁盘

2)获得一个xml工具,比如xmllint和一堆关于XPath的好教程。你知道吗

3)测试和调试XPath,直到找到解决方案。你知道吗

4)如果您有关于XPath的具体问题,请在这里提问。你知道吗

假设你感兴趣的元素是

<div class="summary_text" itemprop="description">
        This documentary highlights the role of education professionals in the Second Republic of Spain as the first independent and free women who broke with the female prototype of that era.
</div>

所以xpath可能是

//div[@itemprop="description"]

或者是英文版的

//div[@itemprop="description"]/p/text()

相关问题 更多 >

    热门问题