• 爬虫-淘宝selenium模拟登录取cookie


    爬虫-淘宝selenium模拟登录取cookie

    # coding=utf-8
    import requests
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    import time, random
    from selenium import webdriver
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.chrome.options import Options
    import re
    import json
    import redis
    
    url = 'https://login.taobao.com/member/login.jhtml'
    #驱动路径,这里根据自己情况更改
    executable_path=r'C:UsersyuanshiAppDataLocalGoogleChromeApplicationchromedriver.exe'
    #查询的内容
    q=input('搜索商品的内容')
    
    #新浪微博的账号密码
    login_name='xxxxx'
    login_pwd ='xxxxxx'
    
    chromeOptions = webdriver.ChromeOptions()
    chromeOptions.add_experimental_option('excludeSwitches', ['enable-automation']) # 设置webdriver为undefind, 因为自动驱动时该值为true
    driver = webdriver.Chrome(chrome_options=chromeOptions,executable_path=executable_path)
    time.sleep(random.uniform(1, 3))
    driver.get(url)
    wait = WebDriverWait(driver,10)
    
    WebDriverWait(driver,60,1).until(EC.presence_of_element_located((By.XPATH,'//*[@class="forget-pwd J_Quick2Static"]')))
    driver.find_element_by_xpath('//*[@class="forget-pwd J_Quick2Static"]').click()
    
    WebDriverWait(driver,60,1).until(EC.presence_of_element_located((By.XPATH,'//a[@class="weibo-login"]')))
    driver.find_element_by_xpath('//a[@class="weibo-login"]').click()
    
    
    
    #新浪登入
    WebDriverWait(driver,60,1).until(EC.presence_of_element_located((By.XPATH,'//input[@name="username"]')))
    driver.find_element_by_name('username').clear()
    driver.find_element_by_xpath('//input[@name="username"]').send_keys(login_name)
    time.sleep(random.uniform(0.3, 1.2))
    
    WebDriverWait(driver,60,1).until(EC.presence_of_element_located((By.XPATH,'//input[@name="password"]')))
    driver.find_element_by_name('password').clear()
    driver.find_element_by_xpath('//input[@name="password"]').send_keys(login_pwd)
    time.sleep(random.uniform(0.3, 1.2))
    
    WebDriverWait(driver,60,1).until(EC.presence_of_element_located((By.XPATH,'//span[@node-type="submitStates"]')))
    driver.find_element_by_xpath('//span[@node-type="submitStates"]').click()
    
    
    cookies_lis=driver.get_cookies()
    print(cookies_lis)
    
    #能用还不点个赞!!!!!
    
  • 相关阅读:
    [2017-7-28]Android Learning Day7
    Codeforces Round #402 (Div. 2) D. String Game
    POJ2411 铺地砖 Mondriaan's Dream
    《大型网站系统架构的演化》
    Nginx 引入线程池,提升 9 倍性能
    《淘宝消息中间件概述》2015-07-11
    主从复制源代码分析
    深入剖析Redis主从复制
    主从复制配置
    Redis启动多端口、运行多实例
  • 原文地址:https://www.cnblogs.com/bladecheng/p/12076718.html
Copyright © 2020-2023  润新知