-
-
Save wismbuhcuk/750b4e4897a0f272021254998cbe0bd8 to your computer and use it in GitHub Desktop.
Scraping websites using Jina AI reader.
This file contains hidden or 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 requests | |
| from typing import Optional | |
| def scrape_website(url: str) -> Optional[str]: | |
| url = f"https://r.jina.ai/{url}" | |
| try: | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| return response.text | |
| else: | |
| print(f"Failed to fetch data. Status code: {response.status_code}") | |
| return None | |
| except requests.exceptions.RequestException as e: | |
| print(f"An error occurred: {e}") | |
| return None | |
| if __name__ == "__main__": | |
| # Add more url to scrape | |
| urls = [ | |
| 'https://blog.zeroinside.id', | |
| 'https://zeroinside.id', | |
| ] | |
| for url in urls: | |
| data = scrape_website(url) | |
| if data: | |
| print(f"Successfully scraped data from #{url}.") | |
| # You can process or save `data` here as needed. | |
| print(data) | |
| else: | |
| print("Failed to scrape data.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment