-
Notifications
You must be signed in to change notification settings - Fork 0
/
bs4test.py
36 lines (33 loc) · 898 Bytes
/
bs4test.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
import requests
import bs4
res = requests.get('https://en.wikipedia.org/wiki/COVID-19_pandemic#Epidemiology')
# https://www.w3.org/testing/')
try:
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
for a in soup.select('a'):
print(a.attrs)
except Exception as err:
print(err)
# import requests
# import bs4
# res = requests.get('https://www.w3.org/testing/')
try:
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
for p in soup.select('p'):
print(p.getText())
except Exception as err:
print(err)
# import requests
res = requests.get('https://www.w3.org/TR/PNG/iso_8859-1.txt')
try:
res.raise_for_status()
iso_file = open('iso_8859.txt', 'wb')
for chunk in res.iter_content(100000):
iso_file.write(chunk)
except Exception as err:
print(err)
finally:
if iso_file is not None:
iso_file.close()