Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import the necessary libraries & modules
- from bs4 import BeautifulSoup
- import requests
- #link to be scraped assigned to a variable
- wiki_page = 'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies'
- #A function that gets the URL of the page to be scraped
- #,gets the html content and uses BeautifulSoup to parse html content
- def make_soup(link):
- get_page = requests.get(link)
- html = get_page.content
- soup = BeautifulSoup(html, 'html.parser')
- return soup
- soup = make_soup(wiki_page)
- #Variable (tickers) which will store the
- tickers = ['']
- #Simple loop to check if my soup is tasty ;)
- for record in soup.find_all('tr'):
- print (record.text)
- #Need help in creating a loop that will append the 'tickers' variable with data from the 'Symbols' column
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement