python - Xpath 问题,试图根据另一个元素的结果定位一个元素
问题描述
我正在尝试使用此代码:
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium import webdriver
from textblob import TextBlob
driver = webdriver.Chrome(executable_path=r'/home/littlejiver/Downloads/chromedriver_linux64/chromedriver')
wait = WebDriverWait(driver, 10)
driver.get("https://zooqle.com/movie/toy-story-l9.html?tg=7")
torrent_titles = driver.find_elements_by_xpath('//*[@id="body_container"]/div/div[1]/div[2]/div/table/tbody/tr/td[2]/a')
torrent_found_on_zooqle = False
for title in torrent_titles:
title_to_check = TextBlob(title.text)
if title_to_check.detect_language() == "en":
if int(title.find_element_by_xpath('//*[@id="body_container"]/div/div/div/div/table/tbody/tr/td[5]/div/div[1]').text) == 10:
title.click()
torrent_found_on_zooqle = True
break
else:
print("not enough seeds")
检查红色突出显示的元素是否通过然后给我黄色突出显示的信息如果它符合条件
现在,我的代码正在做的是检查标题是否为英文,然后检查种子,但检查表中的第一行而不是对应的行。
您可以提供的任何帮助将不胜感激。
谢谢!
小吉弗
解决方案
您必须从 a 标记 xpath,因此您没有正确转到下一个元素。
torrent_titles = driver.find_elements_by_xpath('//table/tbody/tr/td[2]/a')
torrent_found_on_zooqle = False
for title in torrent_titles:
title_to_check = TextBlob(title.text)
if title_to_check.detect_language() == "en":
if title.find_element_by_xpath("following::td[@class='text-nowrap']/div[1]/div[1]").text == '10':
title.click()
torrent_found_on_zooqle = True
break
else:
print("not enough seeds")
推荐阅读
- unity3d - 如何从 TargetHit 脚本调用 Score() 函数到 UpdateUI 脚本?
- r - R:在 gamm (gamcova) 中编程嵌套随机效应
- flutter-web - 颤振网页 | 我不应该在SEO方面建立网站吗?
- codenameone - 代号一我想让工具栏在向上滚动时隐藏
- sql - 为什么我的查询没有提供单一的结果?
- docker - Dockerize dotnet core 2.2 应用程序,nopCommerce Dockerfile 中放置了什么以及为什么行?
- javascript - 如何使用 foreach 循环在其他异步调用中进行异步调用
- r - 使用管道时如何为变量命名
- android - FFmpegAndroid 库在压缩后旋转视频
- android - 用于创建读取或删除电话联系人的应用程序功能