-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_function.py
29 lines (22 loc) · 942 Bytes
/
book_function.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
def extract_info(book_list):
result = []
for book in book_list:
title = book.find("a", {"class" : "N=a:bta.title"}).string
img_src = book.find("div", {"class" : "thumb_type thumb_type2"}).find("img")["src"]
link = book.find("a", {"class" : "N=a:bta.title"})["href"]
author = book.find("dd", {"class" : "txt_block"}).find("a").string.strip()
publisher = book.find("dd", {"class" : "txt_block"}).find("a", {"class" : "N=a:bta.publisher"}).string
if book.find("em", {"class" : "price"}) != None:
price = book.find("em", {"class" : "price"}).string
else:
price = "X"
book_info = {
"title" : title,
"img_src" : img_src,
"link" : link,
"author" : author,
"publisher" : publisher,
"price" : price
}
result.append(book_info)
return result