我正试图从这个网页中删除表格:http://carefacility.doe.louisiana.gov/covid19/List.aspx?parish=Orleans
我使用Selenium是因为我需要从第1页单击到第2页、第3页和第4页,并使用以下代码刮取每页上的表:driver.execute_script(“uu doPostBack('ctl00$MainContent$gvFacilityList','page$2'))
然而,我连第一张桌子都擦不到。下面的代码没有任何输出——它甚至没有打印“hi”
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('http://carefacility.doe.louisiana.gov/covid19/List.aspx?parish=Orleans')
for tr in driver.find_elements_by_xpath('//*[@id="MainContent_gvFacilityList"]/table/tr'):
print("hi!")
tds = tr.find_elements_by_tag_name('td')
print ([td.text for td in tds])
我已经阅读了Stackoverflow上关于这个问题的其他线程,但是没有一个向我解释为什么我没有得到任何结果
如果您想刮去Facility Name
示例代码:
或者,如果您想删除所有日期:
您需要这些导入:
输出:
我找到了一个根本不需要使用XPath的解决方案。相反,我将结果的每一页保存为HTML文件
然后我使用BeautifulSoup刮取每个HTML文件。使用BeautifulSoup创建一个表非常简单,因为您只需要soup.find(“表”),然后将该表保存到数据框中
相关问题 更多 >
编程相关推荐