Understanding Python Web Scraping

Asked 3 months ago, Updated 3 months ago, 10 views

Hello, I'm a beginner who recently started learning python. Let me ask you a question.
I drew a code to extract only the title of the article from Yahoo News.
bs4.FeatureNotFound: Couldn't find a tree builder with the features you
requested: html_parser.Do you need to install a parser library?
will be displayed as .When I ran it in interactive mode, it looked good...
How can I resolve this?

import requests
from bs4 import BeautifulSoup
result=requests.get('https://news.yahoo.co.jp/list/')
soup = BeautifulSoup(result.text, 'html_parser')
midashi_all=soup.find_all('dl', class_='title')
for midashi in midashi_all:
    print(midashi.dt.get_text())

python python3 web-scraping

2022-09-30 11:56

1 Answers

The parser you specified for BeautifulSoup appears to be incorrect. Try html.parser instead of html_parser.

import requests
from bs4 import BeautifulSoup
result=requests.get('https://news.yahoo.co.jp/list/')
soup = BeautifulSoup(result.text, 'html.parser')
midashi_all=soup.find_all('dl', class_='title')
for midashi in midashi_all:
    print(midashi.dt.get_text())


2022-09-30 11:56

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.