-
Notifications
You must be signed in to change notification settings - Fork 1
/
bookDetailed.py
39 lines (34 loc) · 1.41 KB
/
bookDetailed.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
import requests as req
from bs4 import BeautifulSoup as Bs
#detailed book object
class BookDetailed:
baseUrl = "http://libgen.rs/get?&md5="
def __init__(self, queryUrl):
self.bookUrl = self.baseUrl + queryUrl
def parse(self):
response = req.get(self.bookUrl).content
obj = Bs(response, 'html.parser')
downLoadDiv=obj.select("#download h2>a")
downloadLink = downLoadDiv[0]['href']
# downloadLink = obj.select("h2 a")
description = obj.select("p+ div")
resultDict = {}
# if website is overloaded it returns a empty list
if len(description) == 0 and len(downloadLink) == 0:
book={}
resultDict['result'] = "Server Overload"
book['description'] = "Server Error.But you can download the book from the website by clicking below."
book['download'] = "{}".format(self.bookUrl)
resultDict['status'] = "500"
resultDict['bookData']=book #added on 11th july
else:
book = {}
for desc in description:
book['description'] = desc.text.split("Description:")[1]
# for link in downloadLink:
# book['download'] = link['href']
book['download'] = downloadLink
resultDict['bookData'] = book
resultDict['result'] = "success"
resultDict['status'] = "200"
return resultDict