Last active
June 20, 2021 07:45
-
-
Save yongghongg/7f6cfb3faae38ec72ef58cab6572a19d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
def get_stock_list(): | |
# this is the website we're going to scrape from | |
url = "https://www.malaysiastock.biz/Stock-Screener.aspx" | |
response = requests.get(url, headers={'User-Agent':'test'}) | |
soup = BeautifulSoup(response.content, "html.parser") | |
table = soup.find(id = "MainContent2_tbAllStock") | |
# return the result (only ticker code) in a list | |
stock_list = table.find_all('a') | |
return [stock_code.get('href')[-4:] for stock_code in stock_list] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment