我正在尝试提取span标签:Name1之间的文本。该代码具有多个此类标签。
此处的目的是提取Name1等。
from lxml import html
payload = {
"session_key": "random@gmailcom",
"session_password": "random",
"csrfToken": "the token value"
}
session_requests = requests.session()
login_url = "https://www.randomsite.com/login?"
result = session_requests.get(login_url)
tree = html.fromstring(result.text)
authenticity_token = list(set(tree.xpath("//input[@name='csrfToken']/@value")))[0]
result = session_requests.post(
login_url,
data = payload,
headers = dict(referer=login_url)
)
url = 'https://www.randomsite.com/search/results/'
result = session_requests.get(
url,
headers = dict(referer = url)
)
tree = html.fromstring(result.content)
variable = tree.xpath("//span[@class="name.actor-name"]/text()")
预期输出应该是从提到的所有span类中提取的名称。