Python Forum

Full Version: search for a data in my browser via script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys,
Here i am writing a script which will open my chrome browser and opens the URL www.google.com.
But how to search for a data via script.
for example i need to search for 'Rose' in google.com via script.
how to do that?

import webbrowser
url="www.google.com"
chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s'
webbrowser.get(chrome_path)
webbrowser.open(url)
Start with reading some basic tutorials to get taste for web scraping
https://python-forum.io/Thread-Web-Scraping-part-1
https://python-forum.io/Thread-Web-scraping-part-2

Note that depending on site you want to scrap/get data from, there might be API that generally should be used if available.
Hello!

Selenium is a good choice for such a task.
Sorry for the outer how to but I never use it before.
You may like this:

In [1]: from google import search

In [2]: for result in search("Python forum"):
  ...:     print(result)
  ...:     
http://www.python-forum.org/
https://python-forum.io/
https://python-forum.io/Forum-General-Coding-Help
https://python-forum.io/Forum-Homework
https://python-forum.io/Forum-News-and-Discussions
https://python-forum.io/Forum-Tutorials
https://www.python.org/community/
https://www.reddit.com/r/Python/comments/1lqr8j/what_are_the_best_python_forums_to_hang_out_in/
http://www.dreamincode.net/forums/forum/29-python/
http://forums.devshed.com/python-programming-11/
https://www.quora.com/What-are-some-active-Python-forums-for-beginners
http://www.codingforums.com/python/
https://www.python-forum.de/
https://forum.micropython.org/
If you just want to search and display that in browser,
you can do it like this.
import webbrowser

search_word = 'Rose'
url = 'https://www.google.com/#q={}'.format(search_word)
# Open url in new tab in default browser
webbrowser.open_new_tab(url)