Python 3 Web Scraping Script to Scrape Top Articles & News Using HackerNews API & BeautifulSoup4 Library on Command Line

Everyone has every option I have Python 3 Web Scraping Script to Scrape Top Articles & News Using HackerNews API & BeautifulSoup4 Library on Command Line I have the option to write this article. I am writing this article to resolve your doubts. We ask that you understand this article well.

Python 3 Web Scraping Script to Scrape Top Articles & News Using HackerNews API & BeautifulSoup4 Library on Command Line

Python 3 Web Scraping Script to Scrape Top Articles & News Using HackerNews API & BeautifulSoup4 Library on Command Line

pip install bs4
pip install urllib2
import urllib2
from bs4 import BeautifulSoup as bs


def extract_news(url):
    print('HN Top Stories:n'+'-'*50+'n'+'-'*50)
    content = urllib2.urlopen(url).read()
    soup = bs(content,'html.parser')
    for i,tag in enumerate(soup.find_all('td',attrs={'class':'title','valign':''})):
        print(str(i+1)+' :: '+tag.text + 'n' + '-'*51) if tag.text!='More' else ''
        #print(tag.prettify) #find_all('span',attrs={'class':'sitestr'}))
    print('End') 
    
extract_news('https://news.ycombinator.com/')

Read Also: Python 3 Script to Upload File to Dropbox Using Dropbox API V2

Final Words

We hope the Python 3 Web Scraping Script to Scrape Top Articles & News Using HackerNews API & BeautifulSoup4 Library on Command Line article fills your doubts. And let us know if you have any doubts. We resolve your doubts Thank you.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment