Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm downloading books from the website, and almost my code runs smoothly, but when I try to open the pdf Book on my PC. An error generated by Adobe Acrobat Reader that this is not supported file type.

Error Image

Here is the image of the Book formate, and I'm sure my code needs to be a correction because the formate of the book on the website is different from normally PDF Files.

Book Formate Image

Code:

import requests
from bs4 import BeautifulSoup
url = 'https://global.oup.com/education/support-learning-anywhere/key-resources-online/?region=international&utm_campaign=learninganywhere&utm_source=umbraco&utm_medium=display&utm_content=support_learning_key_resources&utm_team=int#Primary'

response = requests.get(url)
soup     = BeautifulSoup(response.content, 'html.parser')
table_data = soup.find_all('td')

books_url_list = []
for link in table_data:
    books_url = link.find('a')['href']
    books_url_list.append(books_url+'.pdf')
    
book = books_url_list[1]
book_response = requests.get(book)

with open('books.pdf', 'wb') as f:
    f.write(book_response.content)

`

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
224 views
Welcome To Ask or Share your Answers For Others

1 Answer

Well, I inspected element from website, then I find no '.pdf' files. We can inspect one book page using following link: https://en.calameo.com/read/000777721d10096b9e9ca?authid=gWc48kAQQoD0&region=international

After inspecting the element, I find is not pdf. It's just an image in the page.

https://p.calameoassets.com/200406174654-2bfa9441783e162c8da42a712feda3e2/p1.svgz

https://p.calameoassets.com/200406174654-2bfa9441783e162c8da42a712feda3e2/p2.svgz

....

https://p.calameoassets.com/200406174654-2bfa9441783e162c8da42a712feda3e2/p98.svgz

And so on.

So, you can write a code to download this image.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...