2017-06-16 56 views
-1

我想循環這個python腳本,所以我可以填寫表單無限次數。當我嘗試循環時,它只會從網站獲得一封確認的電子郵件。我的代碼有什麼問題?如何循環使用機械化的Python腳本?

import mechanize 


#This bot allows for autofill on the ShoezGallery Raffle. 
br = mechanize.Browser() 

response = br.open("https://www.bstnstore.com/yeezy-boost-350-v2-zebra-raffle") 

br.addheaders = [("User-agent","Mozilla/5.0")] 

url = "https://www.bstnstore.com/yeezy-boost-350-v2-zebra-raffle" 

br.select_form(nr=2) 

emailAddress = 'my email' 

br['EMAIL'] = emailAddress #DONT CHANGE 

br['MMERGE3'] = emailAddress #DONT CHANGE 

br.form.find_control(name="MMERGE4", kind="list").value = ["US 9.5 (EU 43 1/3)"] 

br['FNAME'] = 'Julio' 

br['LNAME'] = 'my last name' 

br['MMERGE6'] = 'my phone number' 

br['MMERGE5[addr1]'] = 'my address' 

br['MMERGE5[addr2]'] = 'Floor 1' 

br['MMERGE5[city]'] = 'my town' 

br['MMERGE5[state]'] = 'my state' 

br['MMERGE5[zip]'] = 'my zip' 

br.form.find_control(name="MMERGE5[country]", kind="list").value = ["164"] 


br.submit() 


for i in range(1,1000000): 
    print 'Signed Up' 

回答

0

您想要重複的代碼需要在for循環中。如果您確實希望代碼無限次重複,則還可以考慮將其置於一個while循環中:

import mechanize 

while True: #(The code will repeat forever) 
    #This bot allows for autofill on the ShoezGallery Raffle. 
    br = mechanize.Browser() 

    response = br.open("https://www.bstnstore.com/yeezy-boost-350-v2-zebra-raffle") 

    br.addheaders = [("User-agent","Mozilla/5.0")] 

    url = "https://www.bstnstore.com/yeezy-boost-350-v2-zebra-raffle" 

    br.select_form(nr=2) 

    emailAddress = 'my email' 

    br['EMAIL'] = emailAddress #DONT CHANGE 

    br['MMERGE3'] = emailAddress #DONT CHANGE 

    br.form.find_control(name="MMERGE4", kind="list").value = ["US 9.5 (EU 43 1/3)"] 

    br['FNAME'] = 'Julio' 

    br['LNAME'] = 'my last name' 

    br['MMERGE6'] = 'my phone number' 

    br['MMERGE5[addr1]'] = 'my address' 

    br['MMERGE5[addr2]'] = 'Floor 1' 

    br['MMERGE5[city]'] = 'my town' 

    br['MMERGE5[state]'] = 'my state' 

    br['MMERGE5[zip]'] = 'my zip' 

    br.form.find_control(name="MMERGE5[country]", kind="list").value = ["164"] 


    br.submit() 
    print 'Signed Up'