这篇文章主要介绍了三个python爬虫项目实例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
爬取内涵段子:
#encoding=utf-8import urllib2import reclass neihanba(): def spider(self): ''' 爬虫的主调度器 ''' isflow=True#判断是否进行下一页 page=1 while isflow: url="http://pile(r'<a\s+rel="noreferrer"\s+href="/p/\d+" rel="external nofollow" \s+title=".*?"\s+target="_blank" class="j_th_tit\s+">(.*?)</a>',re.S) titleList=partten.findall(html) rstr=r'<span\s+class="topic-tag"\s+data-name=".*?">#(.*?)#</span>' for title in titleList: title=re.sub(rstr,"",title) self.writePage(title,page) def writePage(self,context,page): fileName="di"+str(page)+"yehtml.txt" with open(fileName,"a") as file: file.writelines(context+"\n")if __name__ == '__main__': name=raw_input("请输入贴吧名:") startPage=raw_input("请输入起始页:") endPage=raw_input("请输入终止页:") t=teiba() t.spider(name,int(startPage),int(endPage))以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。