Python Selenium没有这样的元素,一切都正确。

huangapple go评论127阅读模式
英文:

Pyhton Selenium No such Elements Everytings corrrect

问题

以下是您提供的代码的翻译部分:

我想使用Python和Selenium来抓取 [这个网站](https://www.iddaa.com/canli-skor) 上的比赛结果这些结果存储在表格内的 `tr` 标签中但我已经尝试了几种方法但无法定位表格或其元素我能够定位页面的其他部分我还尝试使用类名和标签名但它们都不起作用请帮忙

我的代码:

s = Service('C:/Users/Sezo/Desktop/verial/Selenium/chromedriver.exe')
driver = webdriver.Chrome(service=s)
driver.get("https://www.iddaa.com/canli-skor")
table_xpath = "/html/body/div[2]/div/div/div/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/table"

table_id = driver.find_element(By.XPATH, table_xpath)
print(len(table_id))

希望这有所帮助。如果您需要更多信息,请告诉我。

英文:

I want to scrape the match results on this website using Python and Selenium. The results are stored in the tr tags within a table, but I've tried several methods and haven't been able to locate the table or its elements. I am able to locate other parts of the page.I have also tried using class name and tag name, but none of them worked. Please help.

My code:

s = Service('C:/Users/Sezo/Desktop/verial/Selenium/chromedriver.exe')
driver = webdriver.Chrome(service=s)
driver.get("https://www.iddaa.com/canli-skor")
table_xpath="/html/body/div[2]/div/div/div/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/table"     
                 

table_id = driver.find_element(By.XPATH,table_xpath) 
print(len(table_id))

答案1

得分: 1

The problem there does not have to do with the waiting but with the iframe which is storing the information you are searching. Before extracting data there you have to change the context of the driver:

driver.switch_to.frame(driver.find_element(By.XPATH, '//iframe[contains(@class, "Iframe-sc")]'))

And then you can search for the element. I would use more deterministic XPATHs which are not so prone to errors:

driver.find_element(By.XPATH, '//td[contains(@class, "score")]')

Anyway you have to verify the xpaths by yourself and find something reliable.

英文:

The problem there does not have to do with the waiting but with the iframe which is storing the information you are searching. Before extracting data there you have to change the context of the driver:

driver.switch_to.frame(driver.find_element(By.XPATH,'//iframe[contains(@class, "Iframe-sc")]'))

And then you can search for the element. I would use more deterministic XPATHs which are not so prone to errors:

driver.find_element(By.XPATH,"//td[contains(@class, 'score')]") 

Anyway you have to verify the xpaths by yourself and find something reliable.

huangapple
  • 本文由 发表于 2023年3月7日 13:53:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658450.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定