用python爬部落格,python爬部落格

來源:互聯網
上載者:User

用python爬部落格,python爬部落格
用python爬部落格by 伍雪穎
以爬王垠的部落格為例:

import reimport urllib2def getHtmlCode(url):return urllib2.urlopen(url).read()def findTitleUrl(htmlString):    regTitleUrl = re.compile("href=\"(.+?)\"")    return regTitleUrl.findall(htmlString)def findTitleContent(htmlString):regTitleContent = re.compile("\">(.+?)</a>")return regTitleContent.findall(htmlString)htmlCode = getHtmlCode('http://www.yinwang.org/')titleContent = findTitleContent(htmlCode)titleUrl = findTitleUrl(htmlCode)for i in range(0, len(titleUrl)):print titleContent[i+3]print titleUrl[i+8]htmlPage = getHtmlCode(titleUrl[i+8])f = open("%s.html"%(titleContent[i+3]),'wb')f.write(htmlPage)f.close



python指令碼學習過程推薦

學習流程:

一:打好基礎
  1.找到合適的入門書籍(推薦Python核心編程2、Dive into Python),大致讀一次,迴圈啊判斷啊,常用類啊,搞懂(太難的跳過)
  2.勤練習python習題(python核心編程2有大量的課後練習題)
  3.加入Python討論群,不懂就問
  4.寫python學習總結性的部落格
  二:開始使用Python做自己的一些日常工作
  比如Python搜尋檔案,Python批量處理等,網路爬蟲等
  三:開始學習Django,Flask,Tornado等架構開發一些web應用
  ----------------------------
資源推薦:
  《簡明Python教程》
《與孩子一起學編程》
《Head First Python 中文版》
《笨辦法學Python》
《Dive.Into.Python中文版(附課程源碼)》
《Python核心編程》
《深入理解Python》
《Python標準庫》
《Python編程指南》
《diango_book中文版》
  更深入系統的學習就看python官網文檔和django官網文檔,勤於學習、總結、練習、實踐就能慢慢學好python的。
 
python抓取csdn部落格內容怎實現?

r = requests.get('blog.csdn.net/u013055678')

這句,csdn防爬蟲做了保護,你必須加個頭
r = requests.get('blog.csdn.net/u013055678',headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0'})
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.