alv67 / packtpub-downloader

Script to download all your books from PacktPub inspired by https://github.com/ozzieperez/packtpub-library-downloader
3 stars 0 forks source link

Get link to Github repository where present #2

Open alv67 opened 3 years ago

alv67 commented 3 years ago

As an example in https://www.packtpub.com/product/hands-on-application-development-with-pycharm/9781789348262 there is a "Download code from GitHub". I need to check for each book if a link is present and in that case add this information to the README.md of the book

code2319 commented 2 years ago

smth like this?

import requests
from bs4 import BeautifulSoup as bs

url = 'https://www.packtpub.com/product/hands-on-application-development-with-pycharm/9781789348262'
r = requests.get(url)
s = bs(r.text, features='lxml')
for i in s.find_all('a', href=True):
    if 'https://github.com/packtpublishing' in i['href']:
        print(f"found url: {i['href']}")