from selenium import webdriver from lxml import etree import requests driver=webdriver.Chrome() driver.get("https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx") 账号=driver.find_element_by_xpath('//*[@id="email"]') 账号.send_keys("xxxxx") 密码=driver.find_element_by_xpath('//*[@id="pwd"]') 密码.send_keys("lhxxx") 验证码=driver.find_element_by_xpath('//*[@id="code"]') a=input("请输入验证码:") 验证码.send_keys(a) 登录=driver.find_element_by_xpath('//*[@id="denglu"]') 登录.click() headers={"user-agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36"} #获取当前网址 url=driver.current_url #获取cookies cookies_1=driver.get_cookies() cookies={} for i in cookies_1: cookies[i["name"]]=i["value"] print(cookies) response=requests.get(url,headers=headers,cookies=cookies).text content=etree.HTML(response) c=content.xpath('//*[@id="mainSearch"]/div[3]/div[1]/div[1]/a/text()')[0] print(c)