Created
February 17, 2020 18:51
-
-
Save benekastah/6ae76a1db77d4f8fa2ca5fd32cb6e476 to your computer and use it in GitHub Desktop.
Basic web scraping using BeautifulSoup
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
from bs4 import BeautifulSoup | |
import requests | |
def scrape_page(url): | |
r = requests.get("http://" + url) | |
data = r.text | |
soup = BeautifulSoup(data) | |
for link in soup.find_all('a'): | |
print(link.get('href')) | |
# do the next line for pages you want to scrape: | |
# scrape_page(lint.get('href')) | |
# DON'T DO THIS FOR ALL LINKS. it could take you anywhere in the internet. | |
# Check if the url is a page you are interested in first. | |
scrape_page("http://example.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment