接口登录淘宝,困难度极高,没有人已经实现过。

淘宝登录selenium 手机版  pc版。

由于每天需要使用ip代理大批量的异地登录淘宝帐号,这种情况必然会出现淘宝滑动验证码,使用ActionChains,

使用手机版m.taobao.login登录,采用短信验证码交互方式登录,获取验证码按钮的点击需要使用TouchActions,不能通过click触发。

但魔蝎科技app也没有提供淘宝在后台处理登录。

#coding=utf8
import platform,time,random,os from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.touch_actions import TouchActions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options import config #print os.getenv('PATH') class BrowserUtil(object):
def __init__(self, is_mobile=0):
self.chrome_options = Options()
self.cookies_dict = {}
self.set_useragent(is_mobile) def __del__(self):
pass
self.driver.quit() def set_options(self,headless=1,display_pictures=0):
# self.chrome_options.binary_location = '/opt/google/chrome/chrome'
self.chrome_options.add_argument('lang=zh_CN.UTF-8')
if headless == 1:
self.chrome_options.add_argument('--headless')
self.chrome_options.add_argument('--disable-gpu')
if not display_pictures:
prefs = {"profile.managed_default_content_settings.images": 2}
self.chrome_options.add_experimental_option("prefs", prefs) def set_proxy(self):
self.chrome_options.add_argument('--proxy-server=http://' + '112.85.84.154:1131') def set_useragent(self,is_mobile):
if not is_mobile:
self.chrome_options.add_argument('user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36"') else:
self.chrome_options.add_argument('user-agent="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Mobile Safari/537.36"')
mobileEmulation = {'deviceName': 'Nexus 6P'}
self.chrome_options.add_experimental_option('mobileEmulation', mobileEmulation) def setup_browser(self,maxsize=1):
self.driver = webdriver.Chrome(chrome_options=self.chrome_options)
if maxsize:
self.driver.maximize_window()
self.driver.set_page_load_timeout(60)
self.driver.implicitly_wait(30) def touch_element(self,element):
TouchActions(self.driver).tap(element).perform() def get_cookies_dict(self):
driver_cookie = self.driver.get_cookies()
for c_dict in driver_cookie:
self.cookies_dict[c_dict['name']] = c_dict['value'] def delete_all_cookies(self):
self.driver.delete_all_cookies() def add_cookie(self,cookie_dict):
"""
:type cookie_dict :dict
""" for k,v in cookie_dict.items():
cookie = {'name':k , 'value':v}
self.driver.add_cookie(cookie) def wait_element_by_id(self, wait_time, element_id):
WebDriverWait(self.driver, wait_time, 0.5).until(EC.presence_of_element_located((By.ID, element_id))) def click_element_by_id(self,element_id):
self.driver.find_element_by_id(element_id).click() def get(self,url):
self.driver.get(url) def save_screen(self,filename):
if platform.system() == 'Windows':
pic_path = config.screen_pic_windows
else:
pic_path = config.screen_pic_linux
if not os.path.exists(pic_path):
os.makedirs(pic_path)
filenamex = pic_path + filename
self.driver.save_screenshot(filenamex) def get_track(self,distance):
track = [ ]
current = 0
mid = distance *4 / 5
t = 0.2
v = 0
while current < distance:
if current < mid:
a = 2
else:
a = -3
v0 = v
v = v0 + a * t
move = v0 * t + 1 / 2 * a * t * t
current += move
track.append(round(move))
return track def drag_element(self,element):
tracks = self.get_track(500) action = ActionChains(self.driver)
action.move_to_element(element).perform()
action.click_and_hold(on_element=element).perform() for x in tracks:
yoffset = random.randint(-10, 10)
time_sleep = random.randint(1,2)/10.0
time_sleep = random.randint(50,100)/1000.0
time.sleep(time_sleep)
action.move_to_element_with_offset(to_element=element, xoffset=x,yoffset=yoffset).perform()
#ActionChains(self.driver).drag_and_drop_by_offset(element,500,yoffset).perform()
action.release(on_element=element).perform()

selenium chrome登陆手机 pc淘宝的更多相关文章

  1. Selenium+Chrome+PhantomJS爬取淘宝美食

    搜索关键字 利用selenium驱动浏览器搜索有关键字,得到查询后的商品列表 分析页码并翻页 得到商品码数,模拟翻页,得到后续页面的商品列表 分析提取商品内容 利用PyQuery分析源码,解析得到商品 ...

  2. Python爬虫系列-Selenium+Chrome/PhantomJS爬取淘宝美食

    1.搜索关键字 利用Selenium驱动浏览器搜索关键字,得到查询后的商品列表 2.分析页码并翻页 得到商品页码数,模拟翻页,得到后续页面的商品列表 3.分析提取商品内容 利用PyQuery分析源码, ...

  3. Selenium+Chrome+PhantomJS 爬取淘宝

    https://github.com/factsbenchmarks/taobao-jingdong 一 简单铺垫 Selenium负责驱动浏览器与python对接 PhantomJS负责渲染解析Ja ...

  4. Selenium模拟浏览器抓取淘宝美食信息

    前言: 无意中在网上发现了静觅大神(崔老师),又无意中发现自己硬盘里有静觅大神录制的视频,于是乎看了其中一个,可以说是非常牛逼了,让我这个用urllib,requests用了那么久的小白,体会到sel ...

  5. 使用selenium模拟浏览器抓取淘宝信息

    通过Selenium模拟浏览器抓取淘宝商品美食信息,并存储到MongoDB数据库中. from selenium import webdriver from selenium.common.excep ...

  6. 16-使用Selenium模拟浏览器抓取淘宝商品美食信息

    淘宝由于含有很多请求参数和加密参数,如果直接分析ajax会非常繁琐,selenium自动化测试工具可以驱动浏览器自动完成一些操作,如模拟点击.输入.下拉等,这样我们只需要关心操作而不需要关心后台发生了 ...

  7. 使用Selenium模拟浏览器抓取淘宝商品美食信息

    代码: import re from selenium import webdriver from selenium.webdriver.common.by import By from seleni ...

  8. Python爬虫学习==>第十二章:使用 Selenium 模拟浏览器抓取淘宝商品美食信息

    学习目的: selenium目前版本已经到了3代目,你想加薪,就跟面试官扯这个,你赢了,工资就到位了,加上一个脚本的应用,结局你懂的 正式步骤 需求背景:抓取淘宝美食 Step1:流程分析 搜索关键字 ...

  9. 3.使用Selenium模拟浏览器抓取淘宝商品美食信息

    # 使用selenium+phantomJS模拟浏览器爬取淘宝商品信息 # 思路: # 第一步:利用selenium驱动浏览器,搜索商品信息,得到商品列表 # 第二步:分析商品页数,驱动浏览器翻页,并 ...

随机推荐

  1. [转载]番茄时间管理法(Pomodoro Technique):一个番茄是如何让你工作更有效率的

    如果你经常读一些关于提高工作效率或时间管理类的博客,一定听说过番茄时间管理法(Pomodoro Technique).这是一种极好的帮助你集中注意力.获得更高工作效率的方法. 基本上,它的实施方法是这 ...

  2. Java编程的逻辑 (74) - 并发容器 - ConcurrentHashMap

    ​本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...

  3. SQL自定义函数

    1,自定义函数--返回单一值 CREATE FUNCTION [dbo].[Round2] ( -- Add the parameters for the function here @p1 sql_ ...

  4. UIWebview交互之自己定义传值跳转

    UIWebview常常会用到和原生页面的跳转.有的可能还须要传值跳转.自己写了一个自己定义跳转的webview,能够跳转到指定控制器并传值,这须要和后台协商好.html中怎样传值跳转,即:html中的 ...

  5. 百度地图Api进阶教程-实例高级操作8.html

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  6. jQuery(九):节点遍历

    一.遍历子元素 children()方法可以用来获取元素的所有子元素,语法如下: 示例: <!DOCTYPE html> <html lang="en"> ...

  7. orcale的over的使用

    --------------------------- 建表 --------------------------- create table test_user( id VARCHAR2(12), ...

  8. Golang (Go语言) Mac OS X下环境搭建 环境变量配置 开发工具配置 Sublime Text 2 【转】

    一.安装Golang的SDK 在官网 http://golang.org/ 直接下载安装包安装即可.下载pkg格式的最新安装包,直接双击运行,一路按照提示操作即可完成安装. 安装完成后,打开终端,输入 ...

  9. static为什么一般与final一起用?

    static和final的意义是不同的,static修饰的时候代表对象是静态的,而final修饰的时候代表对象只能赋值一次,他们连用的时候是因为定义的那个对象既要它是静态的,也要求它的值不能再被修改. ...

  10. 分享:10 大顶级开源 ERP 系统

    10 大顶级开源 ERP 系统 企业资源规划(ERP)和客户关系管理(CRM)系统现在已经成为各种组织和企业的必需品,通过它们,可以轻松实现企业的信息数据标准化.系统运行集成化.业务流程合理化.绩效监 ...