![在这里插入图片描述](https://img-blog.csdnimg.cn/2021060420452918.gif#pic_center)
不开心,就爬取个搞笑段子乐乐,众所周知,Python是写爬虫的利器,今天用Python写一个小爬虫爬一个段子网站的众多搞笑段子。
目标段子网站为“http://ishuo.cn/”,我们先分析其下段子的所在子页的url特点,可以轻易发现为“http://ishuo.cn/subject/”+数字,经过测试发现,该网站的反扒机制薄弱,可以轻易地爬遍其所有站点。
现在利用python的re及urllib库将其所有段子扒下
参考代码:
import sys
import re
import urllib
def gethtml(url):
page=urllib.urlopen