[Python] 纯文本查看 复制代码import re
import os
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver import ChromeOptions
# from exe_js import js1, js2, js3, js4, js5
class OnePlusSpider(object):
def __init__(self):
self.login_url = 'https://account.oneplus.com/cn/login?jump=https%3A%2F%2Faccount.oneplus.com%2Fcn'
self.username = '*****' # 账户名
self.password = '*****' # 密码
# option = ChromeOptions()
# option.add_experimental_option('excludeSwitches', ['enable-automation'])
self.driver = webdriver.Chrome()
self.driver.maximize_window()
# def __del__(self):
# self.driver.close()
@staticmethod
def get_track(distance):
"""
根据偏移量获取移动轨迹
:param distance: 偏移量
:return: 移动轨迹
"""
# 移动轨迹
track = []
# 当前位移
current = 0
# 减速阈值
mid = distance * 4 / 5
# 计算间隔
t = 0.2
# 初速度
v = 0
while current < distance:
if current < mid:
# 加速度为正2
a = 2
else:
# 加速度为负3
a = -3
# 初速度v0
v0 = v
# 当前速度v = v0 + at
v = v0 + a * t
# 移动距离x = v0t + 1/2 * a * t^2
move = v0 * t + 1 / 2 * a * t * t
# 当前位移
current += move
# 加入轨迹
track.append(round(move))
print(track)
print(sum(track))
return track
def one_plus_login(self):
self.driver.get(self.login_url)
self.driver.find_element_by_xpath('//*[@id="input-email"]').send_keys(self.username)
self.driver.find_element_by_xpath('//*[@id="login-password"]').send_keys(self.password)
bnt = self.driver.find_element_by_xpath('//*[@id="nc_1_n1z"]')
ActionChains(self.driver).click_and_hold(bnt).perform()
for x in self.get_track(268):
ActionChains(self.driver).move_by_offset(xoffset=x, yoffset=0).perform()
ActionChains(self.driver).release().perform()
time.sleep(5)
if __name__ == '__main__':
new_spider = OnePlusSpider()
new_spider.one_plus_login()