-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_html.py
50 lines (38 loc) · 1011 Bytes
/
parse_html.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
from bs4 import BeautifulSoup
import json
import requests
import codecs
import sys
UTF8Writer = codecs.getwriter('utf8')
sys.stdout = UTF8Writer(sys.stdout)
def markdown(content):
url = 'http://heckyesmarkdown.com/go/'
payload = {'html': content}
response = requests.post(url, data=payload)
return response
test=False
with open('html_files.txt') as f:
html_file = f.readlines()
i=0;
if not test:
while (i<len(html_file)):
print(i)
out=""
content = open(html_file[i].strip(), 'r').read()
soup = BeautifulSoup(content, 'html.parser')
body = str(soup.find(id="content"))
response = markdown(body)
outname = html_file[i].strip()[0:-5] + ".md"
outfile = open(outname, 'w')
outfile.write(response.text.encode("UTF-8"))
i = i +1
else:
while (i<1):
out=""
content = open(html_file[i].strip(), 'r').read()
soup = BeautifulSoup(content, 'html.parser')
body = str(soup.find(id="content"))
print(str(body))
response = markdown(body)
print(response.text)
i = i +1