Created
November 14, 2011 03:29
-
-
Save AndrewRayCode/1363166 to your computer and use it in GitHub Desktop.
Google search query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import twill.commands | |
import BeautifulSoup | |
import time | |
class browser: | |
def __init__(self, url="http://www.google.com",log = None): | |
self.a=twill.commands | |
self.a.config("readonly_controls_writeable", 1) | |
self.b = self.a.get_browser() | |
self.b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") | |
self.log = log | |
self.b.clear_cookies() | |
self.url=url | |
def googleQuery(self, query="Default Query, not important"): | |
self.b.go(self.url) | |
f = self.b.get_form("f") | |
f["q"] = query | |
self.b.clicked(f, "btnG") | |
self.b.submit() | |
pageContent = self.b.get_html() | |
soup=BeautifulSoup.BeautifulSoup(pageContent) | |
ths = soup.findAll(attrs={ "class" : "r"}, limit=1) | |
for a in ths: | |
print a.findAll('a')[0]['href'] | |
t=browser() | |
t.googleQuery("94103 San Francisco California \"File a complaint\"") | |
time.sleep(1) | |
t.googleQuery("94102 San Francisco California \"File a complaint\"") | |
time.sleep(1) | |
t.googleQuery("94102 San Francisco California \"File a complaint\"") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment