zoukankan      html  css  js  c++  java
  • 【python】列出http://www.cnblogs.com/xiandedanteng/p/中的标题

    # 列出http://www.cnblogs.com/xiandedanteng/p/中的标题
    from bs4 import BeautifulSoup
    import requests
    
    user_agent='Mozilla/4.0 (compatible;MEIE 5.5;windows NT)'
    headers={'User-Agent':user_agent}
    html=requests.get('http://www.cnblogs.com/xiandedanteng/p/',headers=headers)
    #print(html.text);
    soup= BeautifulSoup(html.text,'html.parser',from_encoding='utf-8')
    
    for titleDiv in soup.find_all(class_="postTitl2"):
        link=titleDiv.find('a')
        print(link.string)

    输出:

    C:Usershorn1Desktoppython4>python titles.py
    C:Usershorn1AppDataLocalProgramsPythonPython36libsite-packagess4__init__.py:146: UserWarning: You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.
      warnings.warn("You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.")
    如何安装BeautifulSoup4
    在过去的二十多年的时间里
    linux CentOS6.5 yum安装mysql 5.6(转载&删改)
    Error: Cannot find module 'express'  之  解决方案
    使用Nodejs的Nodemailer通过163信箱发送邮件例程
    Nodejs 天涯帖子《鹿鼎记中计》 柳成萌著 下载爬虫
    使用js的indexOf,lastIndexOf,slice三函数轻易得到url的服务器,路径和页名
    27270图片批量下载爬虫1.00
    转帖:内心若是笃定,何惧未知风雨
    求边长为一的正方体中,面对角线组成的正四面体体积.

    基本达到要求,万里长征又迈出了一小步

  • 相关阅读:
    数据结构总结(UPDATING......)
    课件例题4.11,4.12
    Luogu P1525 关押罪犯
    Luogu P1540 机器翻译
    Luogu P1313 计算系数
    Luogu P1311 选择客栈
    Luogu P1519 穿越栅栏 Overfencing
    Luogu P2863 [USACO06JAN]牛的舞会The Cow Prom
    Tarjan学习笔记
    Luogu P3393 逃离僵尸岛
  • 原文地址:https://www.cnblogs.com/heyang78/p/8668295.html
Copyright © 2011-2022 走看看