Python爬虫 : 基于selenium网页自动化

from selenium import webdriver
import random

driver = webdriver.Chrome()

driver.get(
    "https://www.amazon.co.jp/-/zh/ap/signin?openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.co.jp%2F%3Fref_%3Dnav_signin&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=jpflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&")

input = driver.find_element_by_id("ap_email")


def test1(email):
    input = driver.find_element_by_id("ap_email")

    input.clear()

    input.send_keys(email)

    botton = driver.find_element_by_id('continue')

    botton.click()

    # time.sleep(1)

    res = driver.find_element_by_class_name('a-alert-heading')
    res2 = driver.find_element_by_class_name('a-list-item')
    print(email, res.text, res2.text)
    # print(res2.text)


def generate_random_str(randomlength=16):
    random_str = ''
    base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
    length = len(base_str) - 1
    for i in range(randomlength):
        random_str += base_str[random.randint(0, length)]
    return random_str


if __name__ == '__main__':

    i = 0
    while i < 100:
        test1(generate_random_str(12) + '@yahoo.co.jp')
        test1(generate_random_str(12) + '@candel.co.jp')
        test1(generate_random_str(12) + '@au.com')
        test1(generate_random_str(12) + '@ezweb.nejp')
        i = i + 1
posted @ 2022-05-09 10:59  孤舟浮岸  阅读(122)  评论(0)    收藏  举报