前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python获取淘宝登入cookies

python获取淘宝登入cookies

作者头像
小小咸鱼YwY
发布2020-06-19 15:11:16
2.1K0
发布2020-06-19 15:11:16
举报
文章被收录于专栏:python-爬虫python-爬虫

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

一.代码

代码语言:javascript
复制
# 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()

#最后这里加个time.sleep让页面加载出来
#time.sleep(5)

cookies_lis=driver.get_cookies()
print(cookies_lis)

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

点个赞呗

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一.代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档