scrape ycombinator in python

You can scrape Y Combinator's news website using Python with the help of libraries like requests for fetching the web page and BeautifulSoup for parsing the HTML content. Here's a basic example to scrape the latest news titles from https://news.ycombinator.com:

main.py
import requests
from bs4 import BeautifulSoup

# URL of the Y Combinator news website
url = 'https://news.ycombinator.com/'

# Send a GET request to fetch the web page
response = requests.get(url)

# Parse the HTML content
soup = BeautifulSoup(response.text, 'html.parser')

# Find all the news titles
titles = soup.find_all('a', class_='storylink')

# Display the titles
for index, title in enumerate(titles, start=1):
    print(f'{index}. {title.text}')
456 chars
19 lines

Make sure to install the required libraries by running pip install requests beautifulsoup4.

Please be aware of the website's terms of service and make sure your scraping activities are allowed by the website.

related categories

gistlibby LogSnag