0

How can I use select_form and .form in order to go to the yelp home page, find the search bar, type in 'Dinner' and return the result?

import mechanize
import re

br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

response = br.open('https://www.yelp.com')

br.select_form(nr=0)
br.form['find_desc'] = 'Dinner'         # This is where my issue is
data = br.submit()

print(data)

#prints <response_seek_wrapper at 0x37fde10 whose wrapped object = <closeable_response at 0x3e8c5d0 whose fp = <_io.BufferedReader name=904>>>

for control in br.form.controls:
    print(control)

# prints <TextControl(find_desc=)> <TextControl(find_loc=Irvine, CA)> <HiddenControl(ns=1) (readonly)> <SubmitButtonControl(<None>=submit) (readonly)>

for form in br.forms():
    print(form.name)

# prints None

1 Answer 1

0

Wasn't using an interpreter, also checked the URL to make sure that I was in correct location.

soup = BeautifulSoup(data.read(), 'html.parser')
print(soup)

base_url = br.geturl()
print(base_url)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.