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("")


猜你喜欢

转载自www.cnblogs.com/NiceTime/p/10070177.html