爬取校園新聞首頁的新聞

2022-06-04 22:15:22 字數 1540 閱讀 5556

1. 用requests庫和beautifulsoup庫,爬取校園新聞首頁新聞的標題、鏈結、正文。

import requests

newsurl = ''

res = requests.get(newsurl) # 返回response物件

2. 分析字串,獲取每篇新聞的發布時間,作者,**,攝影等資訊。

info = soup.select("

.show-info

")[0].text

author = info[info.find('

'):].split()[0].lstrip('')

source = info[info.find('

'):].split()[0].lstrip('')

auditing = info[info.find('

'):].split()[0].lstrip('')

photo = info[info.find('

攝影:'):].split()[0].lstrip('

攝影:'

)

print(author,source,auditing,photo)

3. 將其中的發布時間由str轉換成datetime型別。

爬取校園新聞首頁的新聞

1.用requests庫和beautifulsoup庫,爬取校園新聞首頁新聞的標題 鏈結 正文 show info。2.分析info字串,獲取每篇新聞的發布時間,作者,攝影等資訊。import requests newsurl res requests.get newsurl 返回response物...

爬取校園新聞首頁的新聞

1.用requests庫和beautifulsoup庫,爬取校園新聞首頁新聞的標題 鏈結 正文 show info。import requests from bs4 import beautifulsoup newsurl res requests.get newsurl res.encoding ...

爬取校園新聞首頁的新聞

1.用requests庫和beautifulsoup庫,爬取校園新聞首頁新聞的標題 鏈結 正文 show info。2.分析info字串,獲取每篇新聞的發布時間,作者,攝影等資訊。import requests from bs4 import beautifulsoup from datetime ...