程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python crawls to the official website of Chongqing Jiaotong University

編輯:Python

This paper is finally updated at 1163 Days ago, , The information may have developed or changed .

Climb to the main news of current politics on the homepage of the official website of Chongqing Jiaotong University , And extract information , Will be the time of the current political news 、 Title all export display

Code

import requests
from urllib import request
from bs4 import BeautifulSoup
def main():
url = "http://news.cqjtu.edu.cn/rss.htm"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
page = request.Request(url, headers=headers)
page_info = request.urlopen(page).read()
soup = BeautifulSoup(page_info, 'html.parser')
news_titles = soup.select("#ywDiv_0 a")
news_titles.extend(soup.select("#JxDiv_0 a"))
news_titles.extend(soup.select("#JDiv_0 a"))
news_titles.extend(soup.select("#JKDiv_0 a"))
print(type(news_titles))
for news in news_titles:
#print(news)
title = news.get_text()
link = news.get("href")
data = {"title": title, "link": "http://news.cqjtu.edu.cn"+link}
print(data)
main()

Running results

Post Views: 370


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved