Lesson 40 of 55 · Python
Web Scraping with requests and BeautifulSoup
Duration: 20 minutes
Lesson 40 of 55 · Python
Duration: 20 minutes
requests fetches the HTML, while BeautifulSoup parses it into a searchable structure.\n\npython\nimport requests\nfrom bs4 import BeautifulSoup\n\nurl = 'https://quotes.toscrape.com/'\nresponse = requests.get(url)\nresponse.raise_for_status()\n\nsoup = BeautifulSoup(response.text, 'html.parser')\nquotes = soup.select('.quote .text')\nfor q in quotes[:5]:\n print(q.get_text())\n\n\nAlways respect a site’s robots.txt and terms of service when you scrape.\n