【发布时间】:2021-01-06 16:03:43
【问题描述】:
我是使用 python 的业余爱好者,我正在尝试使用 selenium 从下面的 html 中抓取 url。
<a class="" href="#" style="text-decoration: none; color: #1b1b1b;" onclick="toDetailOrUrl(event, '1641438','')">[안내] 빗썸 - 빗썸 글로벌 간 간편 가상자산 이동 서비스 종료 안내</a>
一般情况下,我想获取的链接url就在'href='旁边,但那个html中只有“#”。
当我运行下面的代码时,这是使用 selenium 抓取给定 html 的常用方法,它返回一个 https://cafe.bithumb.com/view/boards/43。但这正是我在“driver.get()”中输入的内容,我不想要。
url = "https://cafe.bithumb.com/view/boards/43"
driver=webdriver.Chrome('chromedriver.exe')
driver.get(url)
driver.implicitly_wait(30)
bo =driver.find_element_by_xpath("//tbody[1]/tr[@style='cursor:pointer;border-top:1px solid #dee2e6;background-color: white']/td[2]/a")
print(bo.get_attribute('href'))
我想要的是https://cafe.bithumb.com/view/board-contents/1641438。当您单击与我上面写的 xpath 对应的项目时,您可以获取此 url。
我想要这个 url 使用 selenium 或其他编程方式,不需要打开 chrome 并在地址栏中输入 url,然后使用鼠标单击......就像那样。
不错
【问题讨论】: