Aug-23-2023, 07:09 AM
(Aug-23-2023, 12:04 AM)cormanstan Wrote: It just appears that I'm being blocked by the website so no data is being passed along. Is this correct? Any suggestions?Set user agent then it will work.
import requests from bs4 import BeautifulSoup url = 'https://www.macrotrends.net/stocks/charts/TSLA/tesla/revenue' headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"} response = requests.get(url, headers=headers) soup = BeautifulSoup(response.content, 'lxml') print(soup.find('h2').text)
Output:Tesla Revenue 2010-2023 | TSLA