Python爬取重庆交通大学官网
本文最后更新于 1830 天前,其中的信息可能已经有所发展或是发生改变。

爬取重庆交通大学官网首页的时政要闻,并提取信息,将时政要闻的时间、标题全部导出显示

代码

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

运行结果

作者:Yuyy
博客:https://yuyy.info
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇