Skip to content

ディープテック経済

市場が追いついたら、もう遅い。

Menu
  • Account
  • Log In
  • Password Reset
  • Profile
  • Register
  • お問い合わせ
  • サンプルページ
Menu

Python code to scrape AI news

Posted on 12/9/202212/9/2022 by DeepRecommend

First, import two libraries, BeautifulSoup and urllib3. Then load the web page using the PoolManager class in urllib3. It then uses BeautifulSoup to parse the HTML code and extract the information it needs.

import bs4
import urllib3

http = urllib3. PoolManager()

# Load a web page
response = http.request('GET', 'http://www.example.com/ai-news')

# Parsing HTML code
soup = bs4. BeautifulSoup(response.data, 'html.parser')

# Extract AI News Titles
titles = soup.find_all('h2')
for title in titles:
    print(title.text)

# Extract AI News article text
articles = soup.find_all('p')
for article in articles:
    print(article.text)

The above code uses BeautifulSoup to extract an element enclosed in h2 tags in HTML and display its text. It also extracts the element enclosed in the p tag as well and displays its text. In this way, you can scrape the AI news title and article body from the web page.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • News (2)
  • Technology (8)
    • AI (5)
    • Brain (3)
    • Quantum (1)
  • Uncategorized (22)
  • Value (6)

Archives

  • May 2023 (1)
  • April 2023 (10)
  • March 2023 (5)
  • February 2023 (9)
  • January 2023 (62)
  • December 2022 (20)
  • November 2022 (1)
© 2026 ディープテック経済 | Powered by Minimalist Blog WordPress Theme