@IEATPYTHON/

Energy Diet Webscraper - Real

Python

No description

fork
loading
Files
  • main.py
  • requirements.txt
main.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
from requests_html import HTMLSession
import re
from flask import Flask

counter = 0
allvotes = [] 
voteorganization = [] 
session = HTMLSession()
r = session.get('http://energydiet.canadiangeographic.ca/2019/main/video_gallery')

links = r.html.links
reallinks = list(links)

for i in range(len(reallinks)):
  e = session.get(reallinks[counter])
  votes = [element.text for element in e.html.find(".video_info")] 
  votes = str(votes)
  votes = re.sub(r'.*/', '/', votes)
  votes = votes[85:]
  votes = votes[:-2]

  for i in range(2):
    votes = votes[votes.find("\\") + 1:]
    votes = votes[votes.find("n") + 1:]

  if "8C7" in votes:
    print('\033[93m','\033[1m', votes, '\033[0m')
  else:
    print(votes) 
  
  numvotes = votes[:-6]

  numvotes = votes[votes.find("n")+1:] 
 # print(numvotes)
  allvotes.append(votes)
  #voteorganization.append()
  #print(voteorganization)
  counter = counter + 1

allvotes = str(allvotes)
html = "<h1><"+str(allvotes)+"><h1>"
app = Flask(__name__) 

@app.route("/")
def main():
  return allvotes
if __name__ == '__main__':
  app.run(host='0.0.0.0')