Python 查找html文件中的所有链接并将其存储在数组中
我在用硒。我想保存html页面中数组中的所有链接(部分链接(“”) 我的代码如下所示:Python 查找html文件中的所有链接并将其存储在数组中,python,selenium,Python,Selenium,我在用硒。我想保存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() dr
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)
OP希望
保存所有链接(那些是部分链接(例如https://instagram.com/p/)
在一个数组中。您正在调用示例url的get()