This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMawdoo3.py
46 lines (36 loc) · 1.58 KB
/
Mawdoo3.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
from requests import get
from random import choice
from bs4 import BeautifulSoup
from random import choice
from random import shuffle
class mawdoo():
def __init__(self):
self.url = 'https://mawdoo3.com/'
self.website = get(self.url).content
self.content = BeautifulSoup(self.website, 'html.parser')
self.categories = self.content.find_all("div", {"class":"category"})
self.scrapped_categories = []
self.scrapped_articles = []
def GetArticle(self):
for category in self.categories:
for category_item in category.find_all('li'):
if not category_item.find('a')['href'].startswith('http'):
self.scrapped_categories.append(category_item.find('a')['href'])
shuffle(self.scrapped_categories)
self.Choosen_Category = self.url + choice(self.scrapped_categories)
self.website = get(self.Choosen_Category).content
self.soup = BeautifulSoup(self.website, 'html.parser')
self.articles = self.soup.find("ul", {'class': "row categories-list"}).find_all('a')
self.scrapped_articles = []
for article in self.articles:
if not article['href'].startswith("http"):
self.scrapped_articles.append(article['href'])
shuffle(self.scrapped_articles)
self.OpenArticle(self.url+choice(self.scrapped_articles))
def OpenArticle(self, url):
"""Opens a new tab"""
"""It uses a the default"""
import webbrowser
webbrowser.open_new(url)
if __name__ == '__main__':
mawdoo().GetArticle()