Python Forum
Take a question in a text doc and automatically googling it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Take a question in a text doc and automatically googling it
#1
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!
Reply
#2
I could say Selenium but on my Linux box I can open it like that: google-chrome <URL>
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(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.
Reply
#4
from selenium import webdriver

# somewhere here you can encode the url

driver = webdriver.Chrome()
driver.get(url)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  selenium wait for text question Larz60+ 3 2,562 Oct-25-2021, 09:50 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020