"""
this is a module,多行注释
"""
import re from urllib import request
# BeautifulSoup:解析数据结构 推荐库 Scrapy:爬虫框架
#爬虫,反爬虫,反反爬虫
#ip 封
#代理ip库
class Spider():
url='https://www.panda.tv/cate/lol'
root_pattern='<div class="video-info">([\s\S]*?)</div>'
name_pattern='</i>([\s\S]*?)</span>'
number_pattern='<span class="video-number">([\s\S]*?)</span>' def __fetch_content(self):
r=request.urlopen(Spider.url)
htmls=r.read()
htmls=str(htmls,encoding='utf-8')
return htmls
a=1 def __analysis(self,htmls):
root_html=re.findall(Spider.root_pattern,htmls)
anchors=[]
for html in root_html:
name=re.findall(Spider.name_pattern,html)
number=re.findall(Spider.number_pattern,html)
anchor={'name':name,'number':number}
anchors.append(anchor)
return anchors def __refine(self,achors):
l=lambda anchor:{'name':anchor['name'][0].strip(),'number':anchor['number'][0]}
return map(l,achors) def __sort(self,anchors): anchors=sorted(anchors,key=self.__sord_seed,reverse=True)
return anchors def __show(self,anchors):
for rank in range(0,len(anchors)):
print('rank '+str(rank+1)+':'+anchors[rank]['name']
+' '+anchors[rank]['number']
) def __sord_seed(self,anchor):
r=re.findall('\d*',anchor['number'])
number= float(r[0])
if '万' in anchor['number']:
number*=10000
return number def go(self):
htmls=self.__fetch_content()
anchors=self.__analysis(htmls)
anchors=list(self.__refine(anchors))
anchors=self.__sort(anchors)
self.__show(anchors) splider=Spider()
splider.go()

python实战之原生爬虫(爬取熊猫主播排行榜)的更多相关文章

  1. 『Scrapy』爬取斗鱼主播头像

    分析目标 爬取的是斗鱼主播头像,示范使用的URL似乎是个移动接口(下文有提到),理由是网页主页属于动态页面,爬取难度陡升,当然爬取斗鱼主播头像这么恶趣味的事也不是我的兴趣...... 目标URL如下, ...

  2. 【Python数据分析】简单爬虫 爬取知乎神回复

    看知乎的时候发现了一个 “如何正确地吐槽” 收藏夹,里面的一些神回复实在很搞笑,但是一页一页地看又有点麻烦,而且每次都要打开网页,于是想如果全部爬下来到一个文件里面,是不是看起来很爽,并且随时可以看到 ...

  3. python实战项目 — 使用bs4 爬取猫眼电影热榜(存入本地txt、以及存储数据库列表)

    案例一: 重点: 1. 使用bs4 爬取 2. 数据写入本地 txt from bs4 import BeautifulSoup import requests url = "http:// ...

  4. 爬虫之selenium爬取斗鱼主播图片

    这是我GitHub上简单的selenium介绍与简单使用:https://github.com/bwyt/spider/tree/master/selenium%E5%9F%BA%E7%A1%80 & ...

  5. selenium,webdriver爬取斗鱼主播信息 实操

    from selenium import webdriver import time from bs4 import BeautifulSoup class douyuSelenium(): #初始化 ...

  6. 如何利用Python网络爬虫爬取微信朋友圈动态--附代码(下)

    前天给大家分享了如何利用Python网络爬虫爬取微信朋友圈数据的上篇(理论篇),今天给大家分享一下代码实现(实战篇),接着上篇往下继续深入. 一.代码实现 1.修改Scrapy项目中的items.py ...

  7. 如何用Python网络爬虫爬取网易云音乐歌曲

    今天小编带大家一起来利用Python爬取网易云音乐,分分钟将网站上的音乐down到本地. 跟着小编运行过代码的筒子们将网易云歌词抓取下来已经不再话下了,在抓取歌词的时候在函数中传入了歌手ID和歌曲名两 ...

  8. Python爬虫 - 爬取百度html代码前200行

    Python爬虫 - 爬取百度html代码前200行 - 改进版,  增加了对字符串的.strip()处理 源代码如下: # 改进版, 增加了 .strip()方法的使用 # coding=utf-8 ...

  9. python爬虫爬取京东、淘宝、苏宁上华为P20购买评论

    爬虫爬取京东.淘宝.苏宁上华为P20购买评论 1.使用软件 Anaconda3 2.代码截图 三个网站代码大同小异,因此只展示一个 3.结果(部分) 京东 淘宝 苏宁 4.分析 这三个网站上的评论数据 ...

随机推荐

  1. [转帖]linux namespace 和cgroup lxc

    https://blog.csdn.net/xiaoliuliu2050/article/details/53443863 5.1 linux namespace 和cgroup lxc 2016年1 ...

  2. Python的数据结构

    目录 Python内置的数据结构 序列Sequence 映射Mapping 集合Sets Python内置的数据结构 Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python内置的 ...

  3. 实现AJAX的基本步骤

    实现AJAX的基本步骤 要完整实现一个AJAX异步调用和局部刷新,通常需要以下几个步骤: (1)创建XMLHttpRequest对象,也就是创建一个异步调用对象. (2)创建一个新的HTTP请求,并指 ...

  4. 去掉DataTable列中的重复行

    DataTable  dt = ds.Tables[0];    //获得 DataTable  DataView dv = new DataView(dt);DataTable dt2 = dv.T ...

  5. Python:目录和文件的操作模块os.path和OS常用方法

    1.目录和文件的操作模块os.path,在使用之前要先导入:import os.path.它主要有以下几个重要的功能函数: #!/user/bin/python #coding= utf-8 impo ...

  6. bzoj 1050 [HAOI2006]旅行comf (并查集)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1050 思路: 先将每条边的权值排个序优先小的,然后从小到大枚举每一条边,将其存到并查集 ...

  7. 前端学习 -- Css -- 字体

    设置字体颜色,使用color来设置文字的颜色 设置文字的大小,浏览器中一般默认的文字大小都是16pxfont-size设置的并不是文字本身的大小,在页面中,每个文字都是处在一个看不见的框中的我们设置的 ...

  8. hdu 1358 Period 最小循环节

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 分析:已知字符串,求其由最小循环节构成的前缀字符串. /*Period Time Limit: ...

  9. mysql数据库给局域网用户所有的权限

    ERROR 1698 (28000): Access denied for user 'root'@'localhost' 刚装好的服务端时必须用 sudo命令才能登录,不然就报1698的错误 然后就 ...

  10. 使用Sql语句快速将数据表转换成实体类

    开发过程中经常需要根据数据表编写对应的实体类,下面是使用sql语句快速将数据表转换成对应实体类的代码,使用时只需要将第一行'TableName'引号里面的字母换成具体的表名称就行了: declare ...