Try this code and let me know in case of any issues:
links = []
for element in driver.find_elements_by_xpath('//head/*[@href or @src]):
link = element.get_attribute("href")
links.append(element.get_attribute("href")) if link != '' else links.append(element.get_attribute("src"))
To get links from iframes also you might need to add this :
for frame in driver.find_elements_by_tag_name('iframe'):
driver.switch_to_frame(frame)
for element in driver.find_elements_by_xpath('//head/*[@href or @src]):
link = element.get_attribute("href")
links.append(element.get_attribute("href")) if link != '' else links.append(element.get_attribute("src"))
driver.switch_to_default_content()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.