forked from howie6879/magic_google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_search.py
executable file
·68 lines (59 loc) · 2.6 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
import os
import sys
import time
import random
import pprint
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
from MagicGoogle import MagicGoogle
################################################
# """
# cd MagicGoogle
# python Examples/google_search.py
# """
#################################################
# Local proxy server
PROXIES = [{
'http': 'http://127.0.0.1:8118',
'https': 'http://127.0.0.1:8118'
}]
# Or MagicGoogle()
mg = MagicGoogle(PROXIES)
# --------------------------------- Get {'title','url','text'} Code -------------------------------------------- ##
for i in mg.search(query='python', num=1, language='en'):
pprint.pprint(i)
time.sleep(random.randint(1, 5))
# --------------------------------- Get {'title','url','text'} Output ------------------------------------------ ##
# Output
# {'text': 'The official home of the Python Programming Language.',
# 'title': 'Welcome to Python .org',
# 'url': 'https://www.python.org/'}
# --------------------------------- Get first page Code --------------------------------------------------------- ##
for url in mg.search_url(query='python'):
pprint.pprint(url)
time.sleep(random.randint(1, 5))
# --------------------------------- Get first page 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 Code ------------------------------------------------------- ##
for url in mg.search_url(query='python', start=10):
pprint.pprint(url)
# --------------------------------- Get second page 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/'