[Python] Get the main topics of Yahoo News

Purpose of this article

Get the main topics of Yahoo News in Python.

Make sure Python is installed.

> python -V
Python 3.8.2

Install module

requests and beautifulsoup4

> pip install requests beautifulsoup4

Create a news acquisition script

news.py


import requests
from bs4 import BeautifulSoup

html = requests.get('https://news.yahoo.co.jp')

yahoo = BeautifulSoup(html.content, "html.parser")

for title in yahoo.select(".topicsList_main li.topicsListItem a"):
    print(title.getText())

Run

> python news.py
Chinese public vessel invades territory for 2 consecutive days
Gifu shows 5 indicators of "exit strategy"
Mediation interruption Parent "I can't see my child"
Slander to nurses and family Kobe
Congratulations to Mr. Masaon Putin
Seoul entertainment facility banned
Little Richard dies
Yuzuki Muroi and Ryuichi Yoneyama to get married

Recommended Posts

[Python] Get the main topics of Yahoo News
Get the title and delivery date of Yahoo! News in Python
[Python] Get the character code of the file
[Python] Get the main color from the screenshot
[Python] Get the update date of a news article from HTML
Get the contents of git diff from python
[Python] Get / edit the scale label of the figure
Get the caller of a function in Python
the zen of Python
[Python] Get the last updated date of the website
[Python] Get the day of the week (English & Japanese)
Get the update date of the Python memo file.
How to get the number of digits in Python
[Python] Get the official file path of the shortcut file (.lnk)
[Python] Get the text of the law from the e-GOV Law API
[python] Get the list of classes defined in the module
Get the return code of the Python script from bat
Get the size (number of elements) of UnionFind in Python
[Python] Get the list of ExifTags names of Pillow library
Get the operation status of JR West with Python
[Python] Get the number of views of all posted articles
Get the URL of the HTTP redirect destination in Python
Towards the retirement of Python2
About the ease of Python
Get the number of digits
[Python] Get the previous month
About the features of Python
The Power of Pandas: Python
Try to get the function list of Python> os package
Get the number of specific elements in a python list
I want to get the operation information of yahoo route
Get the index of each element of the confusion matrix in Python
Get the source of the page to load infinitely with python.
The story of Python and the story of NaN
Get the number of views of Qiita
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
Get the desktop path in Python
Existence from the viewpoint of Python
Get the weather with Python requests
Get the weather with Python requests 2
pyenv-change the python version of virtualenv
Get the script path in Python
How to get the Python version
Get the attributes of an object
Change the Python version of Homebrew
Get the first element of queryset
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Get the number of Youtube subscribers
Get the desktop path in Python
Get the host name in Python
Python Note: Get the current month
About the basics list of Python basics
Learn the basics of Python ① Beginners
Note: Get the first and last items of Python OrderedDict non-destructively
Try to get a list of breaking news threads in Python.
[Python] How to get the first and last days of the month
[python] Get the rank of the values in List in ascending / descending order
Get and set the value of the dropdown menu using Python and Selenium
Get the number of readers of a treatise on Mendeley in Python