【发布时间】:2021-01-18 00:38:14
【问题描述】:
您好,我做了这段代码,它返回给我一个 li 列表,但我想访问里面提到的每个 a 标签并打开它,如果您有任何建议,我将不胜感激
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import pandas as pd
import time
options = Options()
# Creating our dictionary
all_services = pd.DataFrame(columns=['Motif', 'Description'])
path = "C:/Users/Al4D1N/Documents/ChromeDriver_webscraping/chromedriver.exe"
driver = webdriver.Chrome(options=options, executable_path=path)
driver.get("https://www.mairie.net/national/acte-naissance.htm#plus")
list_of_services = driver.find_elements_by_css_selector(".list-images li")
我知道我需要在每个 list_of_services Item 中进行迭代,但我不知道如何打开每个 a 标记,因为它们都没有可以帮助我区分它们的类或 ID
【问题讨论】:
-
打开每个标签是什么意思?您需要实际的 href 还是只需要标题?
-
实际上,如果您访问该网站,您会在页面下方看到第二个部分,其中包含多个
hrefs,我需要打开每个<a>标记。在每个打开的链接中,我都必须提取特定数据
标签: python selenium selenium-webdriver