用fiddler的composer复制重新发送包没有用,感觉知乎现在是不是没有办法模拟登录了?园子里有大神吗
最近园子里没人玩爬虫吗?
我以前抓过.
懒得做模拟登陆.
就直接登陆一次.吧cookie复制到程序里.跑起来.
用senium模拟浏览器登录,
import requests from selenium import webdriver import time import json def obCookie(): url = "https://www.zhihu.com/" opt = webdriver.ChromeOptions() prefs = {'profile.default_content_setting_values': {'images': 2}} opt.add_experimental_option('prefs', prefs) # opt.add_argument('--headless') driver = webdriver.Chrome(options=opt) print("获取网站cookie。。") driver.get(url) driver.find_element_by_xpath('//*[@id="root"]/div/main/div/div[2]/div/div/div/div[1]/div/div[1]/div[2]/button[1]').click() time.sleep(2) driver.find_element_by_xpath('/html/body/div[5]/div/span/div/div[2]/div/div/div/div[2]/div[1]/form/div[1]/div[2]/div[1]/input').send_keys("账号") driver.find_element_by_xpath('/html/body/div[5]/div/span/div/div[2]/div/div/div/div[2]/div[1]/form/div[2]/div/div[1]/input').send_keys("密码") driver.find_element_by_xpath('/html/body/div[5]/div/span/div/div[2]/div/div/div/div[2]/div[1]/form/button').click() time.sleep(5) cookie_list = driver.get_cookies() driver.close() cookie_dict = {} for i in cookie_list: cookie_dict[i["name"]] = i["value"] cookie_dict = json.dumps(cookie_dict) with open('cookie.txt', 'w+', encoding='utf-8') as f: f.write(cookie_dict) return cookie_dict cookie = obCookie() print(cookie)