BeautifulSoup --爬取页面内容

发布时间:2022-06-27 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了BeautifulSoup --爬取页面内容脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

示例一:

"""
获取福田汽车新闻咨询标题
"""
import requests
from bs4 import BeautifulSoup

res = requests.get("https://www.foton.com.cn/webback/news/newsList")
text = res.content.decode('utf8')
soup = BeautifulSoup(text, features='html.parser')

goods_object_list = soup.find(name='ul', attrs={"class": "newsList w1200"})
list_all = goods_object_list.find_all(name='li')

for item in list_all:
    result = item.find(name='div', attrs={"class": "title"})
    print(result.text)
    print('-' * 30)

示例二:

"""
获取汽车之家的“编辑博客”人员信息
"""
import requests
from bs4 import BeautifulSoup

res = requests.get("https://www.autohome.com.cn/news/")
text = res.content.decode('gbk')
soup = BeautifulSoup(text, features='html.parser')

area_object = soup.find(name='ul', attrs={"id": "tagInfo"})
list_all = area_object.find_all(name='li')

for item in list_all:
    item1 = item.find(name='div')
    item2 = item1.find(name='a')
    name = item2.text
    print(name)
    print('-' * 30)

脚本宝典总结

以上是脚本宝典为你收集整理的BeautifulSoup --爬取页面内容全部内容,希望文章能够帮你解决BeautifulSoup --爬取页面内容所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: