
也就是说,我们只须要获得所有的轮回遍历所有的页码,就能获得所有的笑话。
膳绫擎的代码优化后:
- from bs4 import BeautifulSoup
- import os
- import requests
- all_url = 'http://xiaohua.zol.com.cn/new/5.html
- '
- def Gethref(url):
- headers = { 'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"}
- html = requests.get(url,headers = headers)
- soup_first = BeautifulSoup(html.text,'lxml')
- list_first = soup_first.find_all('li',class_='article-summary')
- for i in list_first:
- soup_second = BeautifulSoup(i.prettify(),'lxml')
- list_second = soup_second.find_all('a',target = '_blank',class_='all-read')
- for b in list_second:
- href = b['href']
- print(href)
- Gethref(all_url)
应用如下代码,获取完全的笑话地址url
- from bs4 import BeautifulSoup
推荐阅读
【沙龙】51CTO诚邀您9月23号和多位技巧大年夜咖一路聊智能CDN的优化之路,抓紧时光哦! 引子之前的文┞仿我们商量了激发线程安然的原因主如果因为多线程的对共享内存的操作导致的可见性或有>>>详细阅读
本文标题:Python利用Beautifulsoup爬取笑话网站
地址:http://www.17bianji.com/lsqh/37529.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示