-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mocha.py
81 lines (54 loc) · 2.41 KB
/
Mocha.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
77
78
79
80
81
# importing modules
import time
from datetime import datetime
from plyer import notification
import webbrowser
from bs4 import BeautifulSoup
import requests
import random
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
# You can change the end tags to whatever sources you want to recieve in your web results.
end_tags_coding = [': GeeksforGeeks', ': Stack Overflow', ': W3 Schools']
notification.notify(
title = 'Mocha',
message = 'Welcome to your web scraping assistant',
app_icon = None,
timeout = 3,
)
Task = input('\n\nSearch the web or type a URL\n\n: ')
URL = ('https://www.google.com/search?q= ' + Task + '&oq= ' + Task + '&aqs=chrome..69i57.30j0j7&sourceid=chrome&ie=UTF-8' + '')
URL2 = ('https://www.bing.com/search?q= ' + Task + '&qs=n&form=QBRE&sp=-1&lq=0&pq= ' + Task + '&sc=11-17&sk=&cvid=68CFBFF6CEB74EC38F8C1EBEDA82F639&ghsh=0&ghacc=0&ghpl=&adlt=strict&toWww=1&redig=82384E32C28D4032B8627498876A93E4')
if Task.lower().startswith('https'):
URL3 = str(Task)
Extract_Option = input('\n\nWhat would you like to do with this link?:\n\n[1] Extract links\n[2] Extract text\n[3] check connectivity status\n\n: ')
if Extract_Option == '1':
print('\nScraping content...')
time.sleep(2)
r = requests.get(URL3)
soup = BeautifulSoup(r.content, 'html.parser')
for link in soup.find_all('a'):
print(link.get('href'))
spit = input('')
elif Extract_Option == '2':
page = requests.get(URL3)
print('Scraping content...')
time.sleep(2)
soup = BeautifulSoup(page.content, 'html.parser')
lines = soup.find_all('p')
for line in lines:
print(line.text)
spit2 = input('')
elif Extract_Option == '3':
response_code = requests.get(URL3)
if response_code.status_code == 200:
print("\n\nConnectivity Status: Online...")
input2 = input('')
else:
print(f'Connectivity Status: Offline')
input1 = input('')
else:
print('\nSearching the web...')
time.sleep(2)
task_formed = Task + random.choice(end_tags_coding)
webbrowser.open('https://www.google.com/search?q= ' + task_formed + '&oq= ' + task_formed + '&aqs=chrome..69i57.30j0j7&sourceid=chrome&ie=UTF-8' + random.choice(end_tags_coding) + '')