BestPromptFinderBelow is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: Program a web scraper in Python to extract the latest stock prices from specific websites. ### Input: ["AAPL stocks", "MSFT stocks", "FB stocks", "GOOG stocks"] ### Output: import requests from bs4 import BeautifulSoup # input stocks = ["AAPL stocks", "MSFT stocks", "FB stocks", "GOOG stocks"] # process def get_stock_price(stock): url = f" response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') price = soup.find('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'}).find('span').text return price # output for stock in stocks: price = get_stock_price(stock) print(f'The price of {stock} is {price}.')
Find similar in the app →