-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
47 lines (34 loc) · 1.52 KB
/
run.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
import requests
from bs4 import BeautifulSoup
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('base.html')
@app.route('/detik-popular')
def detik_popular():
html_doc = requests.get('https://www.detik.com/terpopuler', params={'tag_from': 'wp_cb_mostPopular_more'})
soup = BeautifulSoup(html_doc.text, 'html.parser')
popular_area = soup.find(attrs={'class': 'grid-row list-content'})
content_item = popular_area.find_all(attrs={'class': 'list-content__item'})
return render_template('detik-scraping.html', content_item=content_item)
@app.route('/kompas-popular')
def kompas_popular():
html_doc = requests.get('https://indeks.kompas.com/terpopuler')
soup = BeautifulSoup(html_doc.text, 'html.parser')
popular_area = soup.find(attrs={'class': 'latest--indeks'})
if popular_area is None:
content_item = 'None'
else:
content_item = popular_area.find_all(attrs={'class': 'article__list'})
print(content_item)
return render_template('kompas-scraping.html', content_item=content_item)
@app.route('/tempo-popular')
def tempo_popular():
html_doc = requests.get('https://www.tempo.co/populer')
soup = BeautifulSoup(html_doc.text, 'html.parser')
popular_area = soup.find(attrs={'class': 'list list-type-1'})
content_item = popular_area.find_all(attrs={'class': 'card card-type-1'})
return render_template('tempo-scraping.html', content_item=content_item)
if __name__ == '__main__':
app.run(debug=True)