【python】列出http://www.cnblogs.com/xiandedanteng/p/中的标题

时间:2023-03-09 16:02:15
【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:\Users\horn1\Desktop\python\4>python titles.py
C:\Users\horn1\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\__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
转帖:内心若是笃定,何惧未知风雨
求边长为一的正方体中,面对角线组成的正四面体体积.

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