采集wordpress

网站开发 9 浏览 1 分钟阅读

目标网站:https://kinsta.com/knowledgebase/what-is-taxonomy/

一、如何同时采集h2,h3,p标签?
使用下面的方法可以,不过如果使用get_text(),连p标签也去掉了。

from urllib.request import urlopen #获取请求打开网页的库
from bs4 import BeautifulSoup #获取解析网页的库

def get_detail(url):
    # artitle = []
    # html = getHTMLText(url)
    print("正在获取文章详情页的信息......")
    # 爬取网页源代码信息
    html=urlopen(url)#获取html结构与内容
    bs0bj=BeautifulSoup(html,'html.parser')
    # 标签参数tag
    tagList=bs0bj.findAll({"h2","h3","p"})#返回一个包含HTML文档h1标题标签的列表
    print(tagList)
    # print(tagList[0].get_text())  

参考:https://www.jianshu.com/p/22fe0112b061

0

  1. This post has no comment yet

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

相关文章