欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python获取淘宝登入cookies

程序员文章站 2022-05-29 08:17:58
一.代码 `点个赞呗` ......

重点:去新浪微博登入接口登入

一.代码

# 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:\users\yuanshi\appdata\local\google\chrome\application\chromedriver.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)

#能用还不点个赞!!!!!

点个赞呗