【问题标题】:How to loop a Python script that is using Mechanize?如何循环使用 Mechanize 的 Python 脚本?
【发布时间】:2017-11-19 18:10:49
【问题描述】:

我正在尝试循环这个 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'

【问题讨论】:

    标签: python html forms loops mechanize


    【解决方案1】:

    您要重复的代码需要在 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'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多