Python Forum

Full Version: Take a question in a text doc and automatically googling it
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello and thanks for reading. Here is what I have so far:

from urllib.request import urlretrieve
from urllib.parse import urlencode
mydict = {'q': 'whee! Stanford!!!', 'something': 'else'}
qstr = urlencode(mydict)
# str resolves to: 'q=whee%21+Stanford%21%21%21&something=else'
thing = urlretrieve("https://www.google.com/search?" + qstr)
I have a text document (named OCR.txt specifically). I want to take the question that is in it (that is the only
thing inside of it) and then encode it to the google search url. (The random stuff in mydict is just a placeholder).

Also, I then do not know how to have it open chrome and paste the URL into the search to open it automatically.

I found out that the Unix binary, located at /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome, can open URLs without launching a new browser instance. I just do not know how to make it open.

Any help is massively appreciated, I am a beginner and am learning the ropes.

Thanks!
I could say Selenium but on my Linux box I can open it like that: google-chrome <URL>
(Dec-19-2017, 08:19 PM)wavic Wrote: [ -> ]I could say Selenium but on my Linux box I can open it like that: google-chrome <URL>

How would I implement this into my existing code? Thank you for the reply.
from selenium import webdriver

# somewhere here you can encode the url

driver = webdriver.Chrome()
driver.get(url)