• python3爬虫例子02(获取个人博客园的文章信息)


    #!/usr/bin/env python
    # -*- coding:UTF-8 -*-

    import requests
    from bs4 import BeautifulSoup

    res=requests.get("https://www.cnblogs.com/NiceTime/")
    # c=res.content
    c=res.text
    # print(c)

    #获取文章日期
    soup=BeautifulSoup(c,"html.parser")

    postday=soup.find_all(class_="dayTitle")
    # for i in postday:
    # pday=i
    # print(pday.a.string)

    #获取文章标题
    posttitle=soup.find_all(class_="postTitle")
    # for i in posttitle:
    # ptitle=i
    # print(ptitle.a.string)

    #获取文章摘要
    postcorn=soup.find_all(class_="c_b_p_desc")
    # for i in postcorn:
    # ptitle=i
    # print(pcorn.contents[0])

    for day,title,corn in zip(postday,posttitle,postcorn):
    # pcorn=i
    print(day.a.string)
    print(title.a.string)
    print(corn.contents[0].string)
    print("")


  • 相关阅读:
    奶酪真香
    规格说明书
    33
    111
    出题
    随笔 01
    我爱奶酪
    用户规格说明书
    第二次结对作业
    结对作业1
  • 原文地址:https://www.cnblogs.com/NiceTime/p/10070177.html
Copyright © 2020-2023  润新知