forked from aruancaf/stock-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.py
17 lines (14 loc) · 1.01 KB
/
scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from bs4 import BeautifulSoup
import requests
import constants
urls = ["https://finance.yahoo.com/gainers", "https://finance.yahoo.com/screener/predefined/undervalued_growth_stocks", "https://finance.yahoo.com/screener/predefined/day_gainers", "https://finance.yahoo.com/screener/predefined/growth_technology_stocks", "https://finance.yahoo.com/screener/predefined/most_actives", "https://finance.yahoo.com/screener/predefined/undervalued_large_caps", "https://finance.yahoo.com/screener/predefined/aggressive_small_caps", "https://finance.yahoo.com/screener/predefined/small_cap_gainers"]
def active_stocks():
scraped_stocks = constants.STOCKS_TO_CHECK
for url in urls:
soup = BeautifulSoup(requests.get(url).text, 'html.parser')
results = soup.find(id="Lead-5-ScreenerResults-Proxy")
assets = soup.get_text()
for result in results.find_all('a'):
href = result['href']
if '=' in href: scraped_stocks.append(href[href.find('=') + 1:])
return list(set(scraped_stocks))