-
Notifications
You must be signed in to change notification settings - Fork 0
/
request2.py
28 lines (22 loc) · 967 Bytes
/
request2.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
import requests
import csv
qoute_list=[]
author_list=[]
for i in range(1,11):
qoutes=requests.get(f'https://quotes.toscrape.com/page/{i}/')
for line in qoutes.text.split('\n'):
if '<span class="text" itemprop="text">' in line:
line=line.replace('<span class="text" itemprop="text">“', '').replace('”</span>', '').strip()
qoute_list.append(line)
for line in qoutes.text.split('\n'):
if '<span>by <small class="author" itemprop="author">' in line:
line=line.replace('<span>by <small class="author" itemprop="author">', '').replace('</small>','').strip()
author_list.append(line)
zipped=zip(author_list,qoute_list)
head=['author','qoute']
# with open('qoutes_doc.csv','w',encoding='utf-8') as csvfile:
# csvwriter= csv.writer(csvfile)
# csvwriter.writerow(head)
for row in list(zipped):
print(list(row))
# csvwriter.writerow(list(row))