【问题标题】:Selenium Python How to get web content from href without click on itSelenium Python如何从href获取网页内容而不点击它
【发布时间】:2018-03-22 22:52:37
【问题描述】:

我已经使用 Selenium 和 Python 登录了网络。现在我想找到所有href链接并下载/保存链接的网页而不使用.click()。 href 类似于

<a href="project.cfm?CFID=162805&amp;CFTOKEN=98566707&amp;fromlist=1&amp;project_refid=10700290" target="_parent">sth (2) - 2 xox | oo - xx dd </a>

【问题讨论】:

标签: python selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

首先您可以使用以下链接获取链接

listOFLinks =driver.find_elements_by_xpath("//a")

然后遍历列表

for link in listOFLinks
url = link.getAttribute("href");

您可以根据需要打印 url 变量或将其保存到数组中

【讨论】:

  • 这不会按要求保存网页。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-05
  • 1970-01-01
  • 1970-01-01
  • 2011-01-23
  • 1970-01-01
相关资源
最近更新 更多