Python selenium get cookie iQIYI / iQIYI comics (both general) login account

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"
}
# Get cookie # !! need to fill out the account password 
DEF get_cookies ():

    Drive = webdriver.Chrome ( ) Baidu build their own environment #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 " account password " )
    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 ( ' account ' ) # account 
    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 ( ' password ' ) # password 

    B = drive.find_element_by_link_text ( " Login " )
    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 ()   # get cookie and return 
    drive.quit ()
     return Cookies

# Use cookie can request a web page # the request url into iQIYI official website re-get_cookies () to get to the cookie iQIYI video official website 
DEF getHtml (cookies_list):
    JAR = {}
     # segment can be integrated into a cookie requests cookies dictionary used 
    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)

# This version is to obtain cookie according to their own computer, or if it is caused by unfamiliar computer account verification, validation will slide! This procedure No sliders break, please use this computer if the login account to log often appear. . . . Please indicate the source

Guess you like

Origin www.cnblogs.com/HugJun/p/12059889.html