Created
May 27, 2022 02:03
-
-
Save mm-uddin/ae8b2e4b35170a6eb85bb559daf09817 to your computer and use it in GitHub Desktop.
Retrieve urls from a Book Website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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