Skip to content

Instantly share code, notes, and snippets.

@mm-uddin
Created May 27, 2022 02:03
Show Gist options
  • Save mm-uddin/ae8b2e4b35170a6eb85bb559daf09817 to your computer and use it in GitHub Desktop.
Save mm-uddin/ae8b2e4b35170a6eb85bb559daf09817 to your computer and use it in GitHub Desktop.
Retrieve urls from a Book Website
import re
import requests
r = requests.get('https://books.toscrape.com/?fbclid=IwAR1hTa4-2TV1MTpTqfqNgTThdZKCyttb4fJyX05zPoHXdZEM_RefG5iDI5U')
url_pattern = re.compile('<a href="(.*?)"')
result = re.findall(url_pattern, r.text)
f = open("myfile.txt", "w")
for i in range(0, len(result)):
f.write(result[i])
f.write('\n')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment