【问题标题】:how to find tags in bs4.element.ResultSet type object如何在 bs4.element.ResultSet 类型对象中查找标签
【发布时间】:2020-01-12 10:02:21
【问题描述】:

我正在学习/进行网络抓取并遇到一个问题,我有一个 bs4.element.ResultSet 类型的对象 其中包含一些 div 标签,我想像在bs4.BeautifulSoup 类型对象中那样提取它

这是我要提取的 HTML 代码 sn-p

我想要突出显示的代码

原来如此

from bs4 import BeautifulSoup
import requests
url = 'https://www.simplilearn.com/resources'
result = requests.get(url)
web_page = result.content
soup = BeautifulSoup(web_page, 'html.parser')
article = soup.findAll(class_='contentBySegment') #that gives me bs4.element.ResultSet 

然后,我尝试使用 find 方法,但它不起作用,而是出现错误。 我的目标是获取文章主题名称 可以在该代码的这一部分中看到

那么,我该怎么办

【问题讨论】:

  • 请发布可重现的示例和代码。

标签: python beautifulsoup tags


【解决方案1】:
from bs4 import BeautifulSoup
import requests

r = requests.get("https://www.simplilearn.com/resources")
soup = BeautifulSoup(r.text, 'html.parser')

for item in soup.findAll("h4", {'class': 'content-title'}):
    print(item.text)

输出:

How to Become a Certified ScrumMaster
Top 20 Agile Scrum Master Interview Questions & Answers
Free eBook: Guide To Scrum Methodology
The Importance of Machine Learning for Data Scientists
Introduction to Data Science: A Tutorial for Beginners
The Roadmap to a Successful Data Science Career With the PG Program From Simplilearn    
Google Discontinued RHS Ads: How Does This Affects Online Marketers?
Penguin 4.0 Update: The Best Advice From Experts You're Not Taking
Digital Marketing Career Guide: A Playbook to Becoming a Digital Marketing Specialist   
Cyber Security Tutorial: The A to Z to get started
What is Computer Security?
Cybersecurity Career Guide: A Comprehensive Playbook to Becoming A Cybersecurity Expert 
12 Reasons to Get a TOGAF Certification
ITIL: Key Concepts and Summary
Free eBook: Enterprise Architecture Salary Report
Project Management Learning Series: Fast Tracking Versus Crashing
Top 10 Reasons to Get a PRINCE2 Certification
Free Mind-map: PMP Certification
Prepare for Important Salesforce Interview Questions and Answers
Salesforce Developer Certification: an overview
Free eBook: Salesforce Developer Salary Report
Top IT Certification Courses For a Rewarding Career
AWS Careers: A Good Move for Cloud Computing Enthusiasts
AWS Career Guide: A Comprehensive Playbook To Becoming an AWS Solution Architect        
Reskilling the Government Workforce for the Digital Age
How important is the Abraham Maslow’s motivation theory in developing the project team  
Report: The Future of IT Jobs in India
Upskilling for the Fourth Industrial Revolution
Selling Your Idea to Leadership
IDC Study: How Blended Learning Impacts Training Success
The Top 5 Myths of Digital Transformation
Course Announcement: Simplilearn’s Introduction to Digital Transformation
Skilling 4.0: A Study on Digital Readiness
4 Great Ways to Usher in National Technology Day
Go Programming Language: An Introduction
40+ Resources to Help You Learn Java Online

【讨论】:

  • 老兄!!谢谢,但我还需要那些红色矩形的代码列表,所以我该怎么做才能使用内容标题类提取这些文章主题
猜你喜欢
  • 2016-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-18
  • 1970-01-01
  • 2014-01-24
  • 2013-12-08
相关资源
最近更新 更多