-
Notifications
You must be signed in to change notification settings - Fork 109
/
google_search.py
executable file
·76 lines (61 loc) · 2.14 KB
/
google_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Created by howie.hu at 2021-12-18.
Description: example
Changelog: all notable changes to this file will be documented
"""
import pprint
import random
import time
from magic_google import MagicGoogle
################################################
# """
# cd magic_google
# python examples/google_search.py
# """
#################################################
PROXIES = [{"http": "http://127.0.0.1:1087", "https": "http://127.0.0.1:1087"}]
# Or MagicGoogle()
mg = MagicGoogle(PROXIES)
# The first page of results
# result = mg.search_page(query='python')
# print(result)
#
# time.sleep(random.randint(1, 5))
# Get {'title','url','text'}
for i in mg.search(query="python", num=1, language="en"):
pprint.pprint(i)
time.sleep(random.randint(1, 5))
# Output
# {'text': 'The official home of the Python Programming Language.',
# 'title': 'Welcome to Python .org',
# 'url': 'https://www.python.org/'}
# Get first page
for url in mg.search_url(query="python"):
pprint.pprint(url)
time.sleep(random.randint(1, 5))
# Output
# 'https://www.python.org/'
# 'https://www.python.org/downloads/'
# 'https://www.python.org/about/gettingstarted/'
# 'https://docs.python.org/2/tutorial/'
# 'https://docs.python.org/'
# 'https://en.wikipedia.org/wiki/Python_(programming_language)'
# 'https://www.codecademy.com/courses/introduction-to-python-6WeG3/0?curriculum_id=4f89dab3d788890003000096'
# 'https://www.codecademy.com/learn/python'
# 'https://developers.google.com/edu/python/'
# 'https://learnpythonthehardway.org/book/'
# 'https://www.continuum.io/downloads'
# Get second page
for url in mg.search_url(query="python", start=10):
pprint.pprint(url)
# Output
# 'https://github.com/python'
# 'https://github.com/python/cpython'
# 'https://www.learnpython.org/'
# 'https://www.raspberrypi.org/documentation/usage/python/'
# 'https://www.reddit.com/r/Python/'
# 'https://www.datacamp.com/courses/intro-to-python-for-data-science'
# 'https://www.coursera.org/learn/python'
# 'https://www.coursera.org/learn/interactive-python-1'
# 'http://abcnews.go.com/US/record-breaking-17-foot-python-captured-south-florida/story?id=51616851'
# 'https://hub.docker.com/_/python/'