python爬虫实列

import re, sys, urllib.request
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
import time  
import re

engines = {
#https://XXX.XXX.com/XXX.html
        'XXX'  : ('https://account.XXX.com/pc/login', 'XXX', re.compile(r'账户名(.*?)被注册'))
}

def request(urlHead, title, re1, phones):
    print('电话 是否已注册')
    driver.get(urlHead)
    driver.find_element_by_id("login_toRegister").click()
    for phone in phones:
        driver.find_element_by_id("Mobile").send_keys(phone)
        driver.find_element_by_name("Password").click()
        time.sleep(1)
        html = driver.execute_script("return document.documentElement.outerHTML")
        try: 
            print(phone+" 账号名"+re1.findall(html)[0]+"被注册")
        except:
            print(phone+" 其他")
        driver.find_element_by_id("Mobile").send_keys(Keys.CONTROL, "a")
    driver.quit()
    print('--------------------')
        
        
def count_sleep():
    global count
    count += 1
    if count%30 == 0:
        time.sleep(10)

def main():
    try:
        phones = open(filename).read().splitlines()
    except:
        print('[!] %s open fail' % filename)
        exit()
    for engine in engines:
        request(*engines[engine], phones)
    

if __name__ == '__main__':
    if len(sys.argv) == 2:
        filename = sys.argv[1]
        print("正在尝试启动浏览器访问......")
        driver = webdriver.Firefox()
        driver.get("https://XXX.XXX.com/")
        print("启动浏览器成功......")
        print("------------------------------------------------------------")
        main()
    else:
        print('使用: %s phones.lst' % sys.argv[0])
        exit()

 

你可能感兴趣的:(python爬虫实列)