对不起,如果我的问题格式是错误的,因为我是新的编程和StackOverFlow。我无法使用类或任何其他方法找到下载按钮。目前正在尝试使用xpath解决问题,但我听说xpath不是可靠的方法。我正试图从wikiloc网站上下载特定位置内的所有轨道路径。登录时可能会出现问题,因为我可能在抓取时未登录。顺便说一句,我主要使用谷歌colab。我的代码如下:
driver.get('https://www.wikiloc.com/wikiloc/start.do')
driver.find_element_by_name('email').send_keys('testacount852')
driver.find_element_by_name('password').send_keys('49Vchu4njDrrT7.')
driver.find_element_by_id('submit-button').click()
time.sleep(10)
driver.get("https://www.wikiloc.com/trails/outdoor/france/brittany")
links = []
temp_links = []
names = []
temp_names = []
for _ in range(4):
temp = driver.find_elements_by_css_selector('a.trail-title.dont-break-out')
temp_links = [x.get_attribute('href') for x in temp]
temp_names = [x.text for x in temp]
links = links+temp_links
names = names+temp_names
try:
driver.find_element_by_class_name('next').click()
time.sleep(2)
except:
break
for link in links:
driver.get(link)
driver.find_element_by_id('download-button').click()
time.sleep(4)
driver.find_element_by_class_name('active').click()
time.sleep(4)
driver.find_element_by_xpath("/html/body/main/div/div[2]/div/div[1]/div/div[2]/div/div[2]/form/div[2]/input").click()
time.sleep(4)
df['Names'] = pd.Series(names)
df['Links'] = pd.Series(links)
df.to_csv('test1.csv')
driver.close()
这是指向我的凭据的链接 [1] :https://i.stack.imgur.com/HZ6bZ.png
youtube上有一个非常好的教程(这个家伙教你如何使用这个非常有趣的饼干点击游戏);它具有try/except功能,下面是我访问selenium项目的转到。我能够让它与下面显示的代码工作,希望这有助于
问题2:
单击下载按钮后,是否没有类名为“active”的webelement
通过这个xpath,您试图在哪个页面“/html/body/main/div/div[2]/div/div[1]/div/div[2]/div/div[2]/form/div[2]/input”中找到什么? ===========================================================================
更新:
好吧,我找到问题了。是验证码破坏了它。我无法登录,下载按钮(xpath)在我登录之前不可用。感谢各位特别帮助我@ShawnRamirez指出验证码
相关问题 更多 >
编程相关推荐