Python selenium获取爱奇艺/爱奇艺漫画(两者通用)登录账号的cookie
from selenium import webdriver import time import requests from requests.cookies import RequestsCookieJar from selenium.webdriver.chrome.options import Options url = 'https://www.iqiyi.com/manhua/reader/18yzmiyv5x_18yz0vp4jt.html' headers = { "Accept-Encoding": "gzip, deflate", "Host": "www.iqiyi.com", "Upgrade-Insecure-Requests": "1", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Accept-Language": "zh-CN,zh;q=0.9", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" } #获取cookie #!!需要填写账号密码 def get_cookies(): drive=webdriver.Chrome() #chromedriver环境自行百度搭建 drive.get('https://www.iqiyi.com/manhua/') eled=drive.find_element_by_link_text("登录") eled.click() time.sleep(3) iframe = drive.find_elements_by_tag_name("iframe")[0] drive.switch_to_frame(iframe) a=drive.find_element_by_link_text("账号密码登录") a.click() time.sleep(2) drive.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[1]/div[1]/div/div[1]/div[2]/input').send_keys('账号')#账号 drive.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[1]/div[1]/div/div[2]/div/input[1]').send_keys('密码')#密码 b=drive.find_element_by_link_text("登录") b.click() drive.switch_to_default_content() time.sleep(2) drive.get('https://www.iqiyi.com/manhua/detail_18yzmiyv5x.html') time.sleep(3) drive.get('https://www.iqiyi.com/manhua/reader/18yzmiyv5x_18yz0vgmzd.html') cookies = drive.get_cookies() #获取cookie并返回 drive.quit() return cookies #使用cookie请求网页 #可把请求url换成爱奇艺官网重新 get_cookies() 即可获取到爱奇艺视频官网的cookie def gethtml(cookies_list): jar = {} #分段的cookie整合成可以被requests使用的cookies字典 for i in cookies_list: # cookies[i['name']] = i['value'] print(i['name'] + ' ' + i['value']) jar[i['name']] = i['value'] data = requests.get(url,headers=headers,cookies=jar) print(data.text) if __name__ == '__main__': cookies_list = get_cookies() print(cookies_list) gethtml(cookies_list)
#此版是根据自己电脑获取cookie,如果是陌生电脑或者引发账号验证,会出现滑块验证!此程序中暂无滑块破解,如有出现请用本电脑的经常登录账号登录。。。。转载请注明出处
本文章仅供学习参考,如有版权侵犯,请联系作者修改,转载请注明出处!