Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Stock Scraper feature #119

Merged
merged 17 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stock names and symbols fetched from wiki
  • Loading branch information
antoniouaa committed Sep 30, 2020
commit 02c630a9e978f79df6809a352fafbcea788f6c90
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/.vscode
**/venv
24 changes: 24 additions & 0 deletions Scripts/Web_Scrappers/s_n_p500/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# S&P 500 scraper

This is a simple web scraper that collects information about the 500 companies listed in the S&P index

## Installation

Create a virtual environment for the script:

python -m venv venv

and activate it:

.\venv\Scripts\activate # Windows
or

source venv\bin\activate # Linux

Install the requirements:

pip install -r requirements.txt

To run the script:

python pycon_proposals.py
30 changes: 30 additions & 0 deletions Scripts/Web_Scrappers/s_n_p500/scrape_stocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import requests
import pprint
from bs4 import BeautifulSoup


english_wiki_endpoint = "https://en.wikipedia.org/w/api.php"

params = {
"action" : "parse",
"format" : "json",
"page" : "List of S&P 500 companies",
"prop" : "text",
}

response = requests.get(english_wiki_endpoint, params=params)
soup = BeautifulSoup(response.content, "lxml")
symbols = set()
for item in soup.find_all("tr")[:501]:
cells = item.find_all("td")[:2]
try:
symbol, company = cells[0].a.text, cells[1].a.text
except:
continue
tupl = (symbol, company)
symbols.add(tupl)


for tupl in sorted(symbols, key=lambda x:x[1]):
print(tupl)
print(len(symbols))