Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
closed by

I'm attempting to make content on Python that auto-fills a structure on this site structure utilizing Mechanize. The content ought to have the option to loop and make limitless sections on the structure since there is no Captcha. 

Despite the fact that I am genuinely new to Python and Mechanize, I know the fundamentals and realize HTML genuinely well yet am as yet searching for help.

Can anyone please help me?

This is what I've done so far...

            import mechanize

            #This bot allows for autofill on the ShoezGallery Raffle.

            browser = mechanize.Browser()

            response = br.open("http://yeezy.shoezgallery.com/")

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

            url = "http://yeezy.shoezgallery.com/"

            browser.select_form(nr=0)

            browser.form['nom'] = Last name 

            browser.form['prenom'] = First Name

            browser.form['mail'] =  my email here

            browser.form['telephone'] = phone number here

            browser.form['taille'] = 4313

            browser.form['pays'] = Etats_Unis

            brower.submit()

            response = browser.open('http://yeezy.shoezgallery.com/')

            print response.read()

closed

4 Answers

0 votes
by (25.7k points)
selected by
 
Best answer

Certainly! It seems like you're working on a Python script using Mechanize to auto-fill a form on a website. Here's a revised version of your code with some improvements and corrections:

import mechanize

# This bot allows for autofill on the ShoezGallery Raffle.

browser = mechanize.Browser()

browser.set_handle_robots(False)  # Ignore robots.txt rules

url = "http://yeezy.shoezgallery.com/"

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

response = browser.open(url)

browser.select_form(nr=0)

browser.form['nom'] = "Last name"

browser.form['prenom'] = "First Name"

browser.form['mail'] = "my email here"

browser.form['telephone'] = "phone number here"

browser.form['taille'] = ["4313"]

browser.form['pays'] = ["Etats_Unis"]

browser.submit()

response = browser.open(url)

print(response.read())

In the revised code: I added browser.set_handle_robots(False) to ignore any robots.txt rules that could potentially block the bot.

I fixed a typo (br to browser) in the line response = br.open("http://yeezy.shoezgallery.com/").

I enclosed the string values (e.g., "Last name", "First Name") in quotes since they appear to be intended as string literals.

I wrapped the numerical value 4313 in a list when setting browser.form['taille'] and "Etats_Unis" in a list when setting browser.form['pays']. This is necessary to match the expected input format of the form.

Lastly, I changed print response.read() to print(response.read()) to comply with Python 3 syntax.

With these changes, your script should be able to auto-fill the form and print the response. Keep in mind that automating form submissions should be done ethically and with the website owner's permission.

0 votes
by (26.4k points)

Your code is doing last things first and you have blended program/browser and br

 browser = mechanize.Browser()

 response = br.open("http://yeezy.shoezgallery.com/")

should be

 br = mechanize.Browser()

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

 response = br.open(url)

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

0 votes
by (15.4k points)
import mechanize

browser = mechanize.Browser()

browser.set_handle_robots(False)

url = "http://yeezy.shoezgallery.com/"

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

response = browser.open(url)

browser.select_form(nr=0)

browser.form['nom'] = "Last name"

browser.form['prenom'] = "First Name"

browser.form['mail'] = "my email here"

browser.form['telephone'] = "phone number here"

browser.form['taille'] = ["4313"]

browser.form['pays'] = ["Etats_Unis"]

browser.submit()

response = browser.open(url)

print(response.read())
0 votes
by (19k points)
import mechanize

browser = mechanize.Browser()

browser.set_handle_robots(False)

url = "http://yeezy.shoezgallery.com/"

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

browser.open(url)

browser.select_form(nr=0)

browser.form['nom'] = "Last name"

browser.form['prenom'] = "First Name"

browser.form['mail'] = "my email here"

browser.form['telephone'] = "phone number here"

browser.form['taille'] = ["4313"]

browser.form['pays'] = ["Etats_Unis"]

browser.submit()

print(browser.open(url).read())

This version further removes unnecessary comments and combines some lines of code while maintaining the same functionality.

Related questions

0 votes
2 answers
asked Sep 2, 2019 in Web Technology by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
asked Aug 28, 2019 in Web Technology by Tech4ever (20.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...