英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论