Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 查找html文件中的所有链接并将其存储在数组中_Python_Selenium - Fatal编程技术网

Python 查找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

我在用硒。我想保存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)

OP希望
保存所有链接(那些是部分链接(例如https://instagram.com/p/)
在一个数组中。您正在调用示例url的
get()