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,如果是陌生電腦或者引發賬號驗證,會出現滑塊驗證!此程序中暫無滑塊破解,如有出現請用本電腦的經常登錄賬號登錄。。。。轉載請注明出處