[Memo] How to use BeautifulSoup4 (3) Display the article headline with class_

Last time I used find_all to display the headings, but this time I use class_ to display the headings. Also, Yahoo! I decided to scrape Japan.

In [1] Import Beautiful Soup and Requests

In[1]


from bs4 import BeautifulSoup
import requests

In [2] Requests on Yahoo! Get the url of Japan and display the text

In[2]


toget_url =requests.get("https://www.yahoo.co.jp/")
toget_url.text

In [3] Analyzed with BeautifulSoup and html.parser

In[3]


soup = BeautifulSoup(toget_url.text,"html.parser")

So far, it's the same as last time except that the variables and urls have been changed.

Search by find_all based on In [4] class_ =

In[4]


heading =soup.find_all(class_="TRuzXRRZHRqbqgLUCCco9")

Yahoo! with developer tools! When I checked the heading of Japan, I found that "TRuzXRRZHRqbqgLUCCco9" was used in the heading. Don't forget _ (underscore) when searching by class_.

Display the contents by turning with the In [5] for statement

In[5]


for heading_name in heading:
    print(heading_name)

The headline can now be displayed.

Recommended Posts

[Memo] How to use BeautifulSoup4 (3) Display the article headline with class_
[Memo] How to use BeautifulSoup4 (2) Display the article headline with Requests
[Memo] How to use BeautifulSoup4 (1) Display html
How to use the generator
How to use the decorator
How to use the __call__ method in a Python class
How to use cron (personal memo)
Python: How to use async with
How to use the zip function
How to use the optparse module
How to use virtualenv with PowerShell
[Memo] How to use Google MµG
How to use FTP with Python
How to use the ConfigParser module
[Python] Explains how to use the format function with an example
How to display the progress bar (tqdm)
[Introduction to Python] How to use class in Python?
How to use the Spark ML pipeline
How to use OpenVPN with Ubuntu 18.04.3 LTS
How to use Cmder with PyCharm (Windows)
[Linux] How to use the echo command
How to use the Linux grep command
How to use Ass / Alembic with HtoA
How to use Japanese with NLTK plot
How to display python Japanese with lolipop
How to use jupyter notebook with ABCI
How to use CUT command (with sample)
How to use the IPython debugger (ipdb)
How to use SQLAlchemy / Connect with aiomysql
How to use JDBC driver with Redash
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
[Python] Explains how to use the range function with a concrete example
How to use GCP trace with open Telemetry
How to use MkDocs for the first time
How to specify the NIC to scan with amazon-dash
[Python] How to change the date format (display format)
Specify the Python executable to use with virtualenv
How to use the graph drawing library Bokeh
How to scrape horse racing data with BeautifulSoup
How to use the Google Cloud Translation API
The easiest way to use OpenCV with python
[Algorithm x Python] How to use the list
How to use tkinter with python in pyenv
How to display images continuously with matplotlib Note
How to Learn Kaldi with the JUST Corpus
How to turn off the scale value display while leaving the grid with matplotlib
How to display in the entire window when setting the background image with tkinter
How to use xml.etree.ElementTree
How to use Python-shell
How to create an article from the command line
How to use tf.data
How to use virtualenv
How to use xgboost: Multi-class classification with iris data
How to use Seaboan
How to use image-match
How to delete the specified string with the sed command! !! !!
How to use shogun
A memo of how to use AIST supercomputer ABCI
How to use Pandas 2
How to use Virtualenv
[Introduction to Python] How to iterate with the range function?