Skip to content

Instantly share code, notes, and snippets.

@yongghongg
Last active June 20, 2021 07:45
Show Gist options
  • Save yongghongg/7f6cfb3faae38ec72ef58cab6572a19d to your computer and use it in GitHub Desktop.
Save yongghongg/7f6cfb3faae38ec72ef58cab6572a19d to your computer and use it in GitHub Desktop.
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