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