PyThon 2.x 简单爬虫 正则匹配

  1. #coding=utf-8  
  2. import urllib  
  3.   
  4.   
  5. url = "http://www.shashou47.com/category/server/linux-centos/"  
  6. html = urllib.urlopen(url).read()  
  7.   
  8. import re  
  9. res_tr1 = r'<a href="(.*?)#respond"'    
  10. m_th1 = re.findall(res_tr1,html)  
  11. for mm in m_th1:  
  12.     print mm  
  13.   
  14. res_tr2 = r' rel="bookmark">(.*?)</a></h2>'    
  15. m_th2 = re.findall(res_tr2,html)  
  16. for mm in m_th2:  
  17.     print unicode(mm,'utf-8')  
shashou47

发表评论取消回复

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  1   博主  1

    • avatar wei 1

      你也再学python呀

        • avatar shashou47 Admin

          @wei 准备搞树莓派的 :lol: :lol: :lol: