Advertisement
Guest User

Wiki Scrape

a guest
Jul 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. #import the necessary libraries & modules
  2. from bs4 import BeautifulSoup
  3. import requests
  4.  
  5. #link to be scraped assigned to a variable
  6. wiki_page = 'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies'
  7.  
  8. #A function that gets the URL of the page to be scraped
  9. #,gets the html content and uses BeautifulSoup to parse html content
  10.  
  11. def make_soup(link):
  12.     get_page = requests.get(link)
  13.     html = get_page.content
  14.     soup = BeautifulSoup(html, 'html.parser')
  15.     return  soup
  16.  
  17. soup = make_soup(wiki_page)
  18.  
  19. #Variable (tickers) which will store the
  20. tickers = ['']
  21.  
  22. #Simple loop to check if my soup is tasty ;)
  23. for record in soup.find_all('tr'):
  24.     print (record.text)
  25.  
  26. #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