1

I am trying to webscrape of 'https://uidb-pbs.tubitak.gov.tr/#tabs-3' website with selenium but I can't get text of neither the table or items of table from web-site. I'm trying to do it like this:

PATH = "C:\Program Files (x86)\chromedriver.exe"
tubitak_ua_driver = webdriver.Chrome(PATH)
tubitak_ua_driver.get("https://uidb-pbs.tubitak.gov.tr/#tabs-3")
project_table = tubitak_ua_driver.find_element_by_xpath('//*[@id="programCagriListTable"]/tbody')
print(project_table.text)

This code doesn't give any error but doesnt give the text either and when I try to get the inner html of the driver I get innerHTML of first tab from website. What is the problem?

3
  • What text did you want from the table? If you want all of it look into pd.read_html(project_table) with import pandas as pd. Commented Jun 14, 2022 at 7:14
  • Do you want the table text or the entire table in a pandas data frame? Commented Jun 14, 2022 at 7:57
  • I want to get some information from the items of the table and I'm also curios about why my code didn't work Commented Jun 14, 2022 at 8:07

2 Answers 2

1

Q : Why did your code not work?

The website is poorly designed, there are multiple tables having the same Id in the web page and your code gets the first one which does not have anything inside it. Hence you were getting empty string.

enter image description here

Q : How do we get the desired table.

The desired table is present in the second instance of the query id in your web page. Get the second instance of the returned element and then you can either get the text or load the entire table in a pandas data frame.

table = driver.find_elements_by_xpath('//*[@id="programCagriListTable"]/tbody')
print(table[1].text)
Sign up to request clarification or add additional context in comments.

Comments

1

The problem is; there are two elements with this xpath '//*[@id="programCagriListTable"]/tbody' so you need to specify the element that you want. For Example: '(//*[@id="programCagriListTable"]/tbody)[1]'

But if you want the text of an element, you must go to element with text that is (//table[@id="programCagriListTable"])[2]//descendant::td and to look over with a for

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.