1. 程式人生 > >python3爬蟲例子02(獲取個人部落格園的文章資訊)

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