I am trying to scrap a website using Python code, following a tutorial, however the website has since been secured with "https" and when running the code it returns the below error occurs.
# -*- coding: utf-8 -*-
#import libraries
import urllib.request as urllib2
from bs4 import BeautifulSoup
#specify the url
quote_page = 'https://www.bloomberg.com/quote/SPX:IND'
#query the website and return the html to the variable ‘page’
page = urllib2.urlopen(quote_page)
#parse the html using beautiful soup and store in variable `soup`
soup = BeautifulSoup(page, 'html.parser')
#Take out the <div> of name and get its value
name_box = soup.find('h1', attrs={'class': 'companyName'})
name = name_box.text.strip() # strip() is used to remove starting and trailing
print(name)
#get the index price
price_box = soup.find('div', attrs={'class':'price__c3a38e1d'})
price = price_box.text
print(price)
See Question&Answers more detail:os