A
A
Amigun2019-05-29 19:30:15
Google
Amigun, 2019-05-29 19:30:15

How to generate query link in google in python?

Let's say I want to request in Google: Dollar rate
If done manually, write "Dollar rate" in Google and copy the link, it looks like this: www.google.ru/search?q=Dollar+rate&oq=Dollar+rate&aqs=chrome.. 69i57j69i59j0l4.3083j0j1&sourceid=chrome&ie=UTF-8
How to generate the same link automatically in python? Not necessarily this particular request, I gave an example. What libraries are there for this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FulTupFul, 2019-05-29
@Amigun

The requests library already knows how to encode urls out of the box

import requests


r = requests.get('https://www.google.com/search', {'q': 'Курс доллара'})

But Google will think that you are a robot and ask you to enter a captcha, so you'd better search through Google for open api exchange rates:
https://www.google.com/search?q=dollar+rate+api&oq...

V
Vladimir Kuts, 2019-05-29
@fox_12

A simple query on Google gives, for example, the following library:
https://python-googlesearch.readthedocs.io/en/latest/
Using it couldn't be easier:

# Get the first 20 hits for: "Breaking Code" WordPress blog
from googlesearch import search
for url in search('"Breaking Code" WordPress blog', stop=20):
    print(url)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question