日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

【python】获取51cto博客的文章列表

發(fā)布時(shí)間:2024/4/14 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【python】获取51cto博客的文章列表 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


python的正則與網(wǎng)頁(yè)操作練習(xí)二:


import?re import?urllib.request#51cto?urlcode=gb18030class?down51web: s_url='' s_blogid='' s_blogpages='' s_html='' s_code='' def?__init__(self,url,code): self.s_url=url self.s_code=codedef?get_html(self): self.s_html=urllib.request.urlopen(self.s_url).read().decode(self.s_code) return?self.s_htmldef?get_page(self,r_page): if?len(self.s_html)?>?0: m_pages=r_page.search(self.s_html) if?m_pages: self.s_blogpages=m_pages.group(1) return?self.s_blogpagesdef?get_blogid(self,r_blogid): if?len(self.s_html)?>?0: m_blogid=r_blogid.search(self.s_html) if?m_blogid: self.s_blogid=m_blogid.group(1).split('/')[1] return?self.s_blogiddef?get_blogpagelist(self): bloglist=[] if?len(self.s_blogid)>0?and?len(self.s_blogpages)>0: for?i?in?range(1,int(self.s_blogpages)+1): bloglist.append(self.s_url+'/'+self.s_blogid+'/p-'+str(i)) return?bloglistdef?get_pagelist(self,r_list,url): bloglist=[] self.s_url=url s_tmphtml=self.get_html() if?len(s_tmphtml)?>?0: bloglist=r_list.findall(s_tmphtml) return?bloglistr_page=re.compile('頁(yè)數(shù)?\(?[0-9]+/([0-9]+)?\)(?=</div>)') r_blogid=re.compile('(?<=<div?class="pages">)<a?href=([^>]*)>')r_list=re.compile('<h3?class="artTitle"><a?href="([^"]*)">([^<]*)</a>')xx='http://hxw168.blog.51cto.com'hxw=down51web(xx,'gb18030') hxw.get_html() #print(hxw.s_html) print(hxw.get_page(r_page)) print(hxw.get_blogid(r_blogid))list=hxw.get_blogpagelist()for?i?in?list: l1=hxw.get_pagelist(r_list,i) for?x?in?l1: print(xx+x[0]+'-------'+x[1])

代碼排版不正常



import?re import?urllib.request #51cto?urlcode=gb18030 class?down51web:s_url=''s_blogid=''s_blogpages=''s_html=''s_code=''def?__init__(self,url,code):self.s_url=urlself.s_code=codedef?get_html(self):self.s_html=urllib.request.urlopen(self.s_url).read().decode(self.s_code)return?self.s_htmldef?get_page(self,r_page):if?len(self.s_html)?>?0:m_pages=r_page.search(self.s_html)if?m_pages:self.s_blogpages=m_pages.group(1)return?self.s_blogpagesdef?get_blogid(self,r_blogid):if?len(self.s_html)?>?0:m_blogid=r_blogid.search(self.s_html)if?m_blogid:self.s_blogid=m_blogid.group(1).split('/')[1]return?self.s_blogiddef?get_blogpagelist(self):bloglist=[]if?len(self.s_blogid)>0?and?len(self.s_blogpages)>0:for?i?in?range(1,int(self.s_blogpages)+1):bloglist.append(self.s_url+'/'+self.s_blogid+'/p-'+str(i))return?bloglistdef?get_pagelist(self,r_list,url):??bloglist=[]self.s_url=urls_tmphtml=self.get_html()if?len(s_tmphtml)?>?0:?bloglist=r_list.findall(s_tmphtml)return?bloglist?r_page=re.compile('頁(yè)數(shù)?\(?[0-9]+/([0-9]+)?\)(?=</div>)') r_blogid=re.compile('(?<=<div?class="pages">)<a?href=([^>]*)>')r_list=re.compile('<h3?class="artTitle"><a?href="([^"]*)">([^<]*)</a>')xx='http://hxw168.blog.51cto.com'hxw=down51web(xx,'gb18030') hxw.get_html() #print(hxw.s_html) print(hxw.get_page(r_page)) print(hxw.get_blogid(r_blogid))list=hxw.get_blogpagelist()for?i?in?list:l1=hxw.get_pagelist(r_list,i)for?x?in?l1:print(xx+x[0]+'-------'+x[1])

?

????


????????

????

????

????



結(jié)果如下:

>>>?(executing?lines?1?to?74?of?"downweb.py") 4 8718136 http://hxw168.blog.51cto.com/8718136/1533205-------【python】簡(jiǎn)單的網(wǎng)頁(yè)內(nèi)容獲取?-?有道翻譯英文 http://hxw168.blog.51cto.com/8718136/1440229-------【文本處理】awk、sed使用?-?二 http://hxw168.blog.51cto.com/8718136/1436143-------【文本處理】sed的理解工具sedsed http://hxw168.blog.51cto.com/8718136/1435310-------【文本處理】awk、sed使用?-?一 http://hxw168.blog.51cto.com/8718136/1424626-------【shell】oracle安裝前環(huán)境設(shè)置 http://hxw168.blog.51cto.com/8718136/1424422-------【oracle】Oracle12c安裝及一些使用問題 http://hxw168.blog.51cto.com/8718136/1419971-------【oracle】系統(tǒng)權(quán)限、對(duì)象權(quán)限、角色 http://hxw168.blog.51cto.com/8718136/1419736-------【oracle】模擬故障?-?參數(shù)修改導(dǎo)致無法啟動(dòng)oracle http://hxw168.blog.51cto.com/8718136/1419733-------【oracle】表空間 http://hxw168.blog.51cto.com/8718136/1419236-------【oracle】數(shù)據(jù)庫(kù)啟動(dòng) http://hxw168.blog.51cto.com/8718136/1410362-------【1】oracle視頻?-?流水帳筆記 http://hxw168.blog.51cto.com/8718136/1410179-------【基礎(chǔ)服務(wù)】dns智能解析、view主從服務(wù)?-.. http://hxw168.blog.51cto.com/8718136/1409219-------【基礎(chǔ)服務(wù)】簡(jiǎn)單理解DNS的遞歸、迭代查詢.. http://hxw168.blog.51cto.com/8718136/1408946-------【基礎(chǔ)應(yīng)用】rsync簡(jiǎn)單使用 http://hxw168.blog.51cto.com/8718136/1408462-------【6】iptables理解?-?淺嘗輒止 http://hxw168.blog.51cto.com/8718136/1408295-------【5】iptables理解?-?mangle表 http://hxw168.blog.51cto.com/8718136/1405101-------【4】iptables理解?-?nat表 http://hxw168.blog.51cto.com/8718136/1404942-------【3】iptables理解?-?filter表 http://hxw168.blog.51cto.com/8718136/1404541-------【2】iptables理解?-?總體印象 http://hxw168.blog.51cto.com/8718136/1404463-------【1】iptables理解?-?練習(xí)環(huán)境搭建 http://hxw168.blog.51cto.com/8718136/1401483-------【5】puppet筆記?-?defined類型、erb模板 http://hxw168.blog.51cto.com/8718136/1397872-------【4】puppet筆記?-??第一個(gè)簡(jiǎn)單模塊 http://hxw168.blog.51cto.com/8718136/1396483-------【4】puppet筆記?-?數(shù)組、類 http://hxw168.blog.51cto.com/8718136/1396308-------【3】puppet筆記?-?變量、if、case、selector http://hxw168.blog.51cto.com/8718136/1395869-------【2】puppet筆記?-?package、service、use.. http://hxw168.blog.51cto.com/8718136/1395357-------【1】puppet筆記?-?file資源 http://hxw168.blog.51cto.com/8718136/1395073-------【基礎(chǔ)】yum本地源?-?yum?puppet-server為例 http://hxw168.blog.51cto.com/8718136/1394312-------【python】操作oracle數(shù)據(jù)庫(kù) http://hxw168.blog.51cto.com/8718136/1394303-------【基礎(chǔ)】LVM簡(jiǎn)單使用?-??擴(kuò)展縮小LV容量 http://hxw168.blog.51cto.com/8718136/1394089-------【基礎(chǔ)】LVM簡(jiǎn)單使用?-??一 http://hxw168.blog.51cto.com/8718136/1393463-------【基礎(chǔ)】linux添加新硬盤 http://hxw168.blog.51cto.com/8718136/1390593-------【8】nagios從零學(xué)習(xí)使用?-?編寫自己的nag.. http://hxw168.blog.51cto.com/8718136/1390357-------【7】nagios從零學(xué)習(xí)使用?-??nrpe插件使用 http://hxw168.blog.51cto.com/8718136/1389588-------【6】nagios從零學(xué)習(xí)使用?-?centreon發(fā)送.. http://hxw168.blog.51cto.com/8718136/1388191-------【5】nagios從零學(xué)習(xí)使用?-?centreon使用c.. http://hxw168.blog.51cto.com/8718136/1387516-------【4】nagios從零學(xué)習(xí)使用?-?centreon安裝過程 http://hxw168.blog.51cto.com/8718136/1382079-------【3】nagios從零學(xué)習(xí)使用?-?監(jiān)控?win主機(jī) http://hxw168.blog.51cto.com/8718136/1380326-------【2】nagios從零學(xué)習(xí)使用?-?cacti做圖 http://hxw168.blog.51cto.com/8718136/1379795-------【shell】使用ping檢測(cè)機(jī)器是否不在線 http://hxw168.blog.51cto.com/8718136/1379586-------【1】nagios從零學(xué)習(xí)使用?-??軟件安裝>>>



轉(zhuǎn)載于:https://blog.51cto.com/hxw168/1533435

總結(jié)

以上是生活随笔為你收集整理的【python】获取51cto博客的文章列表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。