Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dlutor committed Dec 1, 2019
1 parent 0a95c51 commit eb45be1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Binary file added __pycache__/chaoxing.cpython-37.pyc
Binary file not shown.
18 changes: 12 additions & 6 deletions chaoxing.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ def post(self, url, data):

def download(self, url, path='download'):
r = self.get(url)
print(r.headers)
if r.headers['Content-Type'] != 'image/png':
time.sleep(1)
self.download(url, path)
return 0
with open(path, 'wb') as f:
f.write(r.content)
def read(self, path, mode):
with open(path, mode) as f:
data = f.read()
return data
def write_json(self,data,path):
with open(path,'w') as f:
json.dump(data,f)
Expand All @@ -119,15 +122,18 @@ def book(self,url):
print(f'{file_name},共有{pages}页')
pattern='var str = "(.*?)";'
sub_url=re.findall(pattern,r.text)[0]
data=[]
for i in tqdm(range(int(pages))):
down_url = 'http://readsvr.chaoxing.com{}{:0>6d}?zoom=0'.format(sub_url, i+1)
self.download(down_url,self.dirs+str(i+1)+'.png')
self.create_pdf(self.pdf_dir+file_name+'.pdf')
name=self.dirs+str(i+1)+'.png'
self.download(down_url,name)
data.append(name)
self.create_pdf(self.pdf_dir+file_name+'.pdf',data)
print('成功')
def create_pdf(self,pdf_name:str):
def create_pdf(self,pdf_name:str,data:list):
with open(pdf_name,'wb') as f:
p=Path(self.dirs)
data=[str(i) for i in p.iterdir() if i.suffix == ".png"]
# p=Path(self.dirs)
# data=[str(i) for i in p.iterdir() if i.suffix == ".png"]
try:
f.write(img2pdf.convert(data))
for i in tqdm(data):
Expand Down
Binary file added pdf/不发表,就出局.pdf
Binary file not shown.
Binary file added pdf/神奇的自然法则.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
username = 'xxxx'
password = 'xxxxxx'
b = Basic(username, password)
url = 'http://book.chaoxing.com/ebook/detail_8119069820667abc9c104ed611ea97ec98c38a1c8.html'
url = 'http://book.chaoxing.com/ebook/detail_8144456069d6dca7b25f25aee4574f571490e5ff7.html'
b.book(url)

0 comments on commit eb45be1

Please sign in to comment.