【发布时间】:2020-10-22 01:30:44
【问题描述】:
我正在尝试从 HTML 表中提取数据。 成功计算了行,但是当我打印时它不断重复行。 谁能告诉我代码有什么问题? 谢谢。
#counting length of row
rows = len(driver.find_elements_by_xpath('/html/body/form/fieldset/table[2]/tbody/tr/td[3]/table/tbody/tr[5]/td[2]/div/table[1]/tbody/tr[2]/td[1]/table[2]/tbody/tr'))
time.sleep(2)
print(rows)
for r in range(rows):
value=driver.find_element_by_xpath('/html/body/form/fieldset/table[2]/tbody/tr/td[3]/table/tbody/tr[5]/td[2]/div/table[1]/tbody/tr[2]/td[1]/table[2]/tbody/tr["+str(r)+"]')
print(value.text)
#Output:
18 #no of rows
Start of legal relation2/7/2018 #1st row
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
Start of legal relation2/7/2018
sample test case successfully completed
【问题讨论】:
-
网址好吗?
标签: python html selenium-webdriver web-scraping