gpt4 book ai didi

python - 查找html文件中的所有链接并将其存储在数组中

转载 作者:行者123 更新时间:2023-12-01 01:53:29 25 4
gpt4 key购买 nike

我正在使用 Selenium 。我想将所有链接(即部分链接(“https://instagram.com/p/ ”))保存在 html 页面的数组中。

我的代码如下所示:

src = browser.page_source
#here I get the html page
tag = src.findall("https://instagram.com/p/")
tag = []
print(tag)

我想做这样的事情,但不知道该怎么做。

最佳答案

试试这个

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://instagram.com/p/")

a_tag = driver.find_elements_by_xpath("//a[@href]")
links = [tag.get_attribute('href') for tag in a_tag]

print(links)

关于python - 查找html文件中的所有链接并将其存储在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50496439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com