我试图在python中使用selenium从AllTrails.com/us/florida/state-parks提取数据。我需要的是录音资料。当您第一次打开该网站时,它看起来像下图,并且“评论”处于活动状态
感兴趣部分的html代码为:
现在你可以在html中看到“评论”是活动的(我需要活动的录音)
当我实际单击“录制”时,它会激活录制,但当我尝试使用selenium虚拟地“单击”它时,它不会给出错误,但它不会被激活,代码的后续部分也不会工作。我的代码的相关部分如下:
def get_trail_links (driver, trails_url):
time.sleep(1)
driver.get(trails_url)
page_count = 0
#here is where i am trying to click on the "recordings" button, no error happens here.
driver.find_element_by_xpath("//h3[a/@name='Recordings']").click()
recordings = driver.find_elements_by_xpath("//*[@id ='tracks']")
while page_count < 2:
for record in recordings:
#here is where my button won't work because the recordings is not active in the html.
button = driver.find_element_by_xpath("//button[@title='Show more recordings']")
button.click()
time.sleep(1)
page_count += 1
使用此代码。您还可以通过更改while循环中的值来更改按钮单击的次数
PS:执行时,请将可执行路径更改为本地chrome驱动程序路径
相关问题 更多 >
编程相关推荐