mechanize python XE #16
def cli(google,wiki):
browser = mechanize.Browser()
browser.set_handle_robots(False) #Allows everything to be written
cookies = mechanize.CookieJar()
browser.set_cookiejar(cookies)
browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
browser.set_handle_refresh(False) #Sometimes hangs without this
if(google):
query = raw_input("Enter the topic you want to search about: ")
for link in search(query, tld="co.in", num=10, stop=1, pause=2):
print link
if(wiki):
wiki_topic = raw_input('Enter the topic you want to read about: ')
result = wikipedia.page(title=wiki_topic,auto_suggest=True,redirect=True, preload=False)
wiki_content = result.content
print wiki_content