Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Please see attachment The CNN Money’s Market Movers website (https://money.cnn.com/data/hotstocks/ ) tracks the most active stocks on a real time basis. Specifically, the most active, the top gainers...

1 answer below »
  1. Please see attachment


  2. The CNN Money’s Market Movers website (https://money.cnn.com/data/hotstocks/ ) tracks the most active stocks on a real time basis. Specifically, the most active, the top gainers and top losers are listed at any instance in time. You will first write Python scripts that collect the list of most actives, gainers and losers from the above website. Next, your programs should take the ticker symbols and names of these companies (and categories) and build a csv file (called stocks.csv) with data about each stock from the website:

Answered Same Day Dec 02, 2021

Solution

Prasun Kumar answered on Dec 03 2021
144 Votes
INSY5336_KiaThompson


INSY 5336 - Python Programming¶
Fall 2019 - Final Term Project¶
By Kia Thompson¶
Install the additional modules used
    BeautifulSoup - used to parse the web page
    requests - used to download the web page
In [1]:

#Make sure the necessary modules are installed
!pip install BeautifulSoup4
!pip install requests
Requirement already satisfied: BeautifulSoup4 in c:\programdata\anaconda3\lib\site-packages (4.6.3)
Requirement already satisfied: requests in c:\programdata\anaconda3\lib\site-packages (2.21.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\programdata\anaconda3\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in c:\programdata\anaconda3\lib\site-packages (from requests) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\anaconda3\lib\site-packages (from requests) (2018.11.29)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\programdata\anaconda3\lib\site-packages (from requests) (1.24.1)
The required modules, namely, requests, BeautifulSoup and CSV are imported
In [2]:

#Importing the necessary modules
import requests
from bs4 import BeautifulSoup
import csv

Part 1
Python script to collect the list of most actives, gainers and losers from the CNN Money’s Market Movers website
The web page (CNN website) is downloaded using requests li
ary.
Running the web page through Beautiful Soup gives us a BeautifulSoup object, which represents the document as a nested data structure (hereby refe
ed to as soup).
In [3]:

#Lets read the CNN website and make a soup
url = "https:
money.cnn.com/data/hotstocks/"
= requests.get(url)
data = r.text
soup = BeautifulSoup(data)

Here the assumption is that the 3 tables of 'Most Active', 'Top Gainers' and 'Top Losers' will always be in the same order on the CNN web page
In [4]:

#Assuming the 3 tables are in this orde
tables = ['Most Active', 'Top Gainers', 'Top Losers']
flag = 0

A lot is happening in this cell.
    3 dictionaries are initiated. In case of re-run, the dictionaries must be emptied and filled again.
    Assuming there...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here