conda install -c conda-forge googlesearch
, wait for the installer to complete.sudo -H /opt/jupyterhub/bin/python3 -m pip install google
, wait for the installer to complete; if your python kernel is in a different location, then change the install path (the part between -H and -m). If you have a Linux anaconda install, use conda first, if that fails then try pip.Once installed, then you can import the package in the cell below, then run it to test the install:
import googlesearch
if you get an error message from the cell above, it usually means you did not install the package, read the error to debug the install.
If successful then here is the rest of the script
query = "python for data science"
top_level_domain = 'co.in'
language = 'en'
howmany_hits = 100 # This is used to specify the number of results we desire per search block.
search_start = 0 # Begin URL list at this non-404 result
search_end = 15 # End URL list at this non-404 result
how_long_between_http_requests = 2 # Wait time (in seconds) between consecutive HTTP requests.
# If the wait time is too small Google will assume the process is a DoS attack and block your IP address.
#
# syntax:
# search(query, tld=top_level_domain, lang=language, num=howmany_hits, start=search_start, stop=search_end, pause=how_long_between_http_requests)
# produces an iterable (list) of valid URLs containing the search string
#
# Add code to prompt user for a search string, and place that string into `query`
# Add code to prompt user for how many results to return, put that value into `search_end` limit the value to less than 20
for i in googlesearch.search(query, tld=top_level_domain, lang=language, num=howmany_hits,
start=search_start, stop=search_end, pause=how_long_between_http_requests):
print(i)