Python和selenium从webpage获取所有链接

2024-10-16 17:28:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个脚本可以从一个站点下载所有的.csv文件。它是工作正常,但我还需要得到一个列表与网址.csv文件。 下载的代码部分如下:

# Download files according to Xpath in table
def downloadfiles(Xpath):
    global browser
    time.sleep(10);
    # Click csv img
    try:
        browser.find_element_by_xpath(Xpath).click()
        global downloadcount
        downloadcount = downloadcount + 1
        return
    # Element not found
    except NoSuchElementException as e:
        print("Error enxontró csv")
    return

在这里我想我需要做些什么:browser.find_element_by_xpath(Xpath).click() 而不是点击我想得到链接。 代码是用python3.6和selenium编写的。 Xpath是"//*[@id=\"ctl00_ContentPlaceHolder1_ListViewNodos_ctrl0_ListViewArchivosSIN_ctrl0_linkCSV\"]"

如何获取.csv文件的链接列表?在


Tags: 文件csv代码browser列表byreturn链接