from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time
import random
import _thread
totalnum=0 #总行数
currentNum=[0,0,0,0,0,0,0,0] #d当前行数
totalcount=[0]
def isuser(driver,name):
isu = True
email = driver.find_element_by_id("ap_email")
if email is not None:
email.click()
email.clear()
email.send_keys(name)
continue_bu = driver.find_element_by_id('continue') # 找到导出按钮
continue_bu.click()
try:
result = driver.find_element_by_id("signInSubmit")
except NoSuchElementException:
print(name + " 不是亚马逊用户")
return False
print(name + " 是亚马逊用户")
driver.get(
url='https://www.amazon.co.jp/ap/signin?_encoding=UTF8&openid.assoc_handle=jpflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_sel'
'ect&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.n'
'et%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2F'
'www.amazon.co.jp%2Fgp%2Fcart%2Fview.html%3Fie%3DUTF8%26'
'app-nav-type%3Dnone%26dc%3Ddf%26dc%3Ddf%26path%3D%252Fgp%252Fcart%252Fview.html%253Fapp-nav-type%253Dnone%26ref_%3Dcart_empty_sign_in%26useRedire'
'ctOnSuccess%3D1')
return isu
def main(filename,f,cur,thread):
chrome_options = webdriver.ChromeOptions()
chrome_driver = r"C:\Users\59886\Desktop\邮箱采集工具\chromedriver.exe" #指定driver
# chrome_driver = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chrome_driver,options=chrome_options)
driver.get(url='https://www.amazon.co.jp/ap/signin?_encoding=UTF8&openid.assoc_handle=jpflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_sel'
'ect&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.n'
'et%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2F'
'www.amazon.co.jp%2Fgp%2Fcart%2Fview.html%3Fie%3DUTF8%26'
'app-nav-type%3Dnone%26dc%3Ddf%26dc%3Ddf%26path%3D%252Fgp%252Fcart%252Fview.html%253Fapp-nav-type%253Dnone%26ref_%3Dcart_empty_sign_in%26useRedire'
'ctOnSuccess%3D1')
while(cur[thread-1]<totalnum//8*thread):
name = f[cur[thread-1]].strip("\n")
time.sleep(1 + random.randint(1, 3))
if isuser(driver, name):
with open(filename+'--user.txt','a') as f1:
f1.write(name + '\n')
cur[thread-1]+=1
totalcount[0]+=1
return cur
filename=input("请输入文件名:")
# f1=open('user.txt','a')
f=open(filename).readlines()
totalnum=len(f)
currentNum=[0,totalnum//8,totalnum//4,totalnum//8*3,totalnum//2,totalnum//8*5,totalnum//8*6,totalnum//8*7]
# 创建两个线程
try:
_thread.start_new_thread(main, (filename,f, currentNum, 1))
_thread.start_new_thread(main, (filename,f, currentNum, 2))
_thread.start_new_thread(main, (filename,f, currentNum, 3))
_thread.start_new_thread(main, (filename,f, currentNum, 4))
_thread.start_new_thread(main, (filename,f, currentNum, 5))
_thread.start_new_thread(main, (filename,f, currentNum, 6))
_thread.start_new_thread(main, (filename,f, currentNum, 7))
_thread.start_new_thread(main, (filename,f, currentNum, 8))
except:
print ("Error: 无法启动线程")
while totalcount[0]<totalnum:
pass