I am working on a project scraping a table off a web site. I will not be able to give full code as this is a company specific site with a login, hence my choice of Selenium. I have located the table in the HTML code:
class Table:
def __init__(self, driver):
self.driver = driver
def get_row_info(self):
table_id = self.driver.find_element(By.ID, 'dgTickets')
rows = table_id.find_elements(By.TAG_NAME, "tr")
col = []
i = 0
for i in rows[0]:
i+=1
name = i.text()
col.append((name, []))
for j in range(1,len(rows)):
T = rows[j]
i = 0
for t in T.iterchildren():
data = t.text_content()
if i>0:
try:
data = int(data)
except:
pass
col[i][1].append(data)
i+=1
Dict = {title:column for (title, column) in col}
This returns me an error that it is not an iterable value.
I think what I am trying to do here is relatively self explanatory. Primarily, I am trying to return the web table and eventually get it into a pandas dataframe for parsing. Using various methods, I can get the columns to print out their texts, but there seems to be a problem with passing that to a specified column in a table. Here is one way that I have found to return the column:
for row in rows:
col0 = row.find_elements(By.TAG_NAME, "td")[0]
I'm honestly a little lost at this point. Any suggestions for me?
print()andprint(type(...))to see what you have in variables. OR learn how to use debugger.for i in rows[0]: i+=1-rowsis a list but you get first element from listrows[0]and you try to use it as listfor i in rows[0]and when you even get it asithen you treats it as numberi += 1- but later you treats it as objecti.text(). If usingi += 1you try to get next element then it is wrong. OR maybe you have to use the same variable for two differene elemen -i = 0andfor i in rows[0]- but Python can't keep keep two different values in the same variable.DataFrames-