获取博客园本人的积分排名数据:

1. 抓包获取积分排名数据返回接口:http://www.cnblogs.com/belle-ls/mvc/blog/sidecolumn.aspx?blogApp=belle-ls

2. 解析返回的数据,获取积分排名

3. 开启线程,循环打印积分排名信息

from bs4 import BeautifulSoup
import time
import requests
import threading class BlogRankMonitor(object):
"""
获取博客园积分排名
""" def __init__(self, id):
self.urlBasic = 'http://www.cnblogs.com/%s/mvc/blog/sidecolumn.aspx?blogApp=%s'
self.id = id
self.score = 0
self.rank = 0 def get_nums(self, blogs_des):
"""
分割字符串 积分 - 43 排名 - 283325,获取数字
:return:
"""
split_str = blogs_des.split('-')[1].strip()
return split_str def get_blog_ranks(self):
"""
解析页面获取博客积分和排名
:return:
"""
url = self.urlBasic % (self.id, self.id)
res = requests.get(url)
soup = BeautifulSoup(res.text, "lxml")
liScore= soup.find(class_="liScore")
for child in liScore.children:
if u'积分' in child.string:
self.score = self.get_nums(child.string)
elif u'排名' in child.string:
self.rank = self.get_nums(child.string)
print("积分:", blog.score, "排名:", blog.rank, "时间:", time.strftime("%Y-%m-%d %X", time.localtime())) def start_score_rank_thread(self):
t = threading.Thread(target= self.get_blog_ranks())
t.start() if __name__ == '__main__':
blog = BlogRankMonitor('belle-ls') while 1:
blog.start_score_rank_thread()
time.sleep(10) #10s打印一次 """
运行结果:
积分: 45 排名: 0 时间: 2019-02-12 15:57:22
积分: 45 排名: 0 时间: 2019-02-12 15:57:32
积分: 45 排名: 0 时间: 2019-02-12 15:57:42
积分: 45 排名: 0 时间: 2019-02-12 15:57:53
积分: 45 排名: 0 时间: 2019-02-12 15:58:03
....
"""

BeautifulSoup库应用实例的更多相关文章

  1. Python爬虫小白入门(三)BeautifulSoup库

    # 一.前言 *** 上一篇演示了如何使用requests模块向网站发送http请求,获取到网页的HTML数据.这篇来演示如何使用BeautifulSoup模块来从HTML文本中提取我们想要的数据. ...

  2. python爬虫学习之使用BeautifulSoup库爬取开奖网站信息-模块化

    实例需求:运用python语言爬取http://kaijiang.zhcw.com/zhcw/html/ssq/list_1.html这个开奖网站所有的信息,并且保存为txt文件和excel文件. 实 ...

  3. 使用SharePoint Designer定制开发专家库系统实例!

    将近大半年都没有更新博客了,趁这段时间不忙,后续会继续分享一些技术和实际应用.对于Sharepoint的定制开发有很多种方式,对于一般的应用系统,可以使用Sharepoint本身自带的功能,如列表作为 ...

  4. BeautifulSoup库children(),descendants()方法的使用

    BeautifulSoup库children(),descendants()方法的使用 示例网站:http://www.pythonscraping.com/pages/page3.html 网站内容 ...

  5. 网络爬虫BeautifulSoup库的使用

    使用BeautifulSoup库提取HTML页面信息 #!/usr/bin/python3 import requests from bs4 import BeautifulSoup url='htt ...

  6. BeautifulSoup库的使用

    1.简介 BeautifulSoup库也是一个HTML/XML的解析器,其使用起来很简单,但是其实解析网站用xpath和re已经足矣,这个库其实很少用到.因为其占用内存资源还是比xpath更高. '' ...

  7. python下载安装BeautifulSoup库

    python下载安装BeautifulSoup库 1.下载https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/ 2.解压到解压 ...

  8. 基于BeautifulSoup库的HTML内容的查找

    一.BeautifulSoup库提供了一个检索的参数: <>.find_all(name,attrs,recursive,string,**kwargs),它返回一个列表类型,存储查找的结 ...

  9. BeautifulSoup库

    '''灵活又方便的网页解析库,处理高效,支持多种解析器.利用它不用编写正则表达式即可方便的实现网页信息的提取.''' BeautifulSoup库包含的一些解析库: 解析库 使用方法 优势 劣势 py ...

随机推荐

  1. Shiro——认证概述

    认证流程 身份认证流程 首先调用 Subject.login(token) 进行登录,其会自动委托给SecurityManager SecurityManager 负责真正的身份验证逻辑:它会委托给A ...

  2. bootstrap图片切换效果

    <!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8&quo ...

  3. 类的 where T : class 泛型类型约束

    where T : struct | T必须是一个结构类型where T : class T必须是一个类(class)类型where T : new() | T必须要有一个无参构造函数where T ...

  4. 用firebug 进行表单自定义提交

    在一些限制网页功能的场合,例如,防止复制内容,防止重复提交,限制操作的时间段/用户等,网页上一些按钮是灰化的(禁用的),这通常是通过设置元素的 disable属性来实现的.但在后台并没有做相应的功能限 ...

  5. [.net 多线程]Mutex

    Mutex是可以进程间同步的同步基元.   名称 说明 Mutex() 使用默认属性初始化 Mutex 类的新实例. Mutex(Boolean) 使用 Boolean 值(指示调用线程是否应具有互斥 ...

  6. Android TV 开发 (1)

    本文来自网易云社区 作者:孙有军 前言 这里主要记录几个TV问题的解决方案,如果对这个不感兴趣的其实就不用往下看了. 这几天有一个需求就是要求出一个TV版本的app,之前没有具体的了解Tv版的app有 ...

  7. 关于GNU规范的语法扩展

    GNU 是一款能用于构建类 Unix 操作系统的计算机软件合集,由自由软件之父 Richard Stallman 开创,于 1983 年 9 月 27 日对外发布.GNU 完全由自由软件(free s ...

  8. lower_bound下确界

    //lower_bound用于找到首个大于等于某个值的元素 #include<algorithm> #include<iostream> using namespace std ...

  9. clickonce发布方式创建桌面快捷方式

    1.工程属性->发布->选项->清单:创建桌面快捷方式打勾 2.工程属性->应用程序->清单:下拉列表选择Properties\app.manifest(其中的图标可以选 ...

  10. 【BZOJ3622】已经没什么好害怕的了 容斥原理+dp

    Description Input Output Sample Input 4 2 5 35 15 45 40 20 10 30 Sample Output 4 HINT 输入的2*n个数字保证全不相 ...