Difference between revisions of "Python: Google Search"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) (Created page with "Install pendukung pip install beautifulsoup4 pip install google Syntax search(query, tld='com', lang='en', num=10, start=0, stop=None, pause=2.0) query : query string...") |
Onnowpurbo (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Install pendukung | Install pendukung | ||
− | + | pip3 install beautifulsoup4 | |
− | + | pip3 install google | |
Syntax | Syntax | ||
Line 19: | Line 19: | ||
Search google | Search google | ||
− | try: | + | try: |
− | + | from googlesearch import search | |
− | except ImportError: | + | except ImportError: |
− | + | print("No module named 'google' found") | |
+ | |||
+ | # to search | ||
+ | query = "astra" | ||
+ | for j in search(query, tld='com', lang='id', num=10, start=0, stop=None, pause=2.0): | ||
+ | print(j) | ||
+ | |||
+ | |||
+ | ==Pranala Menarik== | ||
− | + | * [[Python]] | |
− | |||
− | |||
− | |||
− |
Latest revision as of 16:52, 12 October 2019
Install pendukung
pip3 install beautifulsoup4 pip3 install google
Syntax
search(query, tld='com', lang='en', num=10, start=0, stop=None, pause=2.0)
query : query string that we want to search for. tld : tld stands for top level domain which means we want to search our result on google.com or google.in or some other domain. lang : lang stands for language. num : Number of results we want. start : First result to retrieve. stop : Last result to retrieve. Use None to keep searching forever. pause : Lapse to wait between HTTP requests. Lapse too short may cause Google to block your IP. Keeping significant lapse will make your program slow but its safe and better option. Return : Generator (iterator) that yields found URLs. If the stop parameter is None the iterator will loop forever.
Search google
try: from googlesearch import search except ImportError: print("No module named 'google' found") # to search query = "astra" for j in search(query, tld='com', lang='id', num=10, start=0, stop=None, pause=2.0): print(j)