目标地址:http://www.espncricinfo.com/champions-league-twenty20-2012/engine/match/574265.html

liz@nb-liz:~$ script pyquery.log2
Script started, file is pyquery.log2
liz@nb-liz:~$ ipython
Python 2.7.3 (default, Jan 2 2013, 16:53:07)
Type "copyright", "credits" or "license" for more information. IPython 1.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details. In [1]: from pyquery import PyQuery as pq # 使用 In [2]: d=pq(url="http://www.espncricinfo.com/champions-league-twenty20-2012/engine/match/574265.html") #取内容 In [6]: d('#inningsBat1')
Out[6]: [<table#inningsBat1.inningsTable>] In [8]: d('#inningsBat1').html()
。。。 In [11]: d('#inningsBat1').find('.playerName').html()
Out[11]: u'<a href="/champions-league-twenty20-2012/content/player/237095.html" target="" title="view the player profile for Murali Vijay" class="playerName">M Vijay</a> ' In [14]: d('#inningsBat1').eq(1).find('.playerName').html() In [18]: t=d('#inningsBat1') In [19]: t
Out[19]: [<table#inningsBat1.inningsTable>] In [20]: t.children()
Out[20]: [<tr>, <tr.inningsHead>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr.inningsComms>, <tr.inningsRow>, <tr>, <tr.inningsRow>] In [22]: t('tr.inningsRow')
Out[22]: [<tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>] In [23]: trs=t('tr.inningsRow') In [24]: trs
Out[24]: [<tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>] In [25]: trs.eq(0).html()
Out[25]: u'<td class="inningsIcon" onclick="ToggleRowVisibility(\'inningsBat1\',3); "><img src="http://i.imgci.com/espncricinfo/col_ps.gif" width="7" height="7" name="inningsBat1.1" class="inningsIcon" alt="View dismissal" title="View dismissal" id="inningsBat1.1" /></td>\n <td width="192" class="playerName"><a href="/champions-league-twenty20-2012/content/player/237095.html" target="" title="view the player profile for Murali Vijay" class="playerName">M Vijay</a> </td>\n <td width="259" class="battingDismissal"> b Ojha </td>\n <td class="battingRuns">39</td>\n <td class="battingDetails">36</td>\n <td class="battingDetails">25</td>\n <td class="battingDetails">5</td>\n <td class="battingDetails">2</td>\n <td class="battingDetails">156.00</td>\n ' In [27]: trs.eq(0).find('.playerName').html()
Out[27]: u'<a href="/champions-league-twenty20-2012/content/player/237095.html" target="" title="view the player profile for Murali Vijay" class="playerName">M Vijay</a> ' In [28]: n1=trs.eq(0).find('.playerName') In [29]: n1.find('a').html()
Out[29]: 'M Vijay' In [34]: trs[0]
Out[34]: <Element tr at 0x968e44c> In [40]: trs
Out[40]: [<tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>, <tr.inningsRow>] In [42]: for i in trs:
print d(i).find('.playerName').find('a').text()
....:
M Vijay
F du Plessis
SK Raina
MS Dhoni
S Badrinath
RA Jadeja
JA Morkel
WP Saha
R Ashwin
BW Hilfenhaus
None
None In [44]: for i in trs:
print d(i).find('.playerName').find('a').text()
print d(i).find('.battingRuns').text()
print d(i).find('.battingDismissal').text()# for...in 结构中用pyquery实例(d)开始找
....: print '\n'
....:
M Vijay
39
b Ojha F du Plessis
52
c Sharma b Malinga SK Raina
8
c Johnson b Malinga MS Dhoni
35
c Smith b Malinga S Badrinath
2
c †Karthik b Smith RA Jadeja
12
run out (†Karthik/Johnson) JA Morkel
0
c Tendulkar b Malinga WP Saha
5
c †Karthik b Malinga R Ashwin
13
not out BW Hilfenhaus
0
not out None
7
(b 1, w 6) None
173
(8 wickets; 20 overs; 100 mins) In [45]: for i in trs:
print 'Player Name:',d(i).find('.playerName').find('a').text()
print 'Batting Runs:',d(i).find('.battingRuns').text()
    print 'Batting Dismissal:',d(i).find('.battingDismissal').text()# for...in 结构中用pyquery实例(d)开始找
print '\n'
....:
Player Name: M Vijay
Batting Runs: 39
Batting Dismissal: b Ojha Player Name: F du Plessis
Batting Runs: 52
Batting Dismissal: c Sharma b Malinga Player Name: SK Raina
Batting Runs: 8
Batting Dismissal: c Johnson b Malinga Player Name: MS Dhoni
Batting Runs: 35
Batting Dismissal: c Smith b Malinga Player Name: S Badrinath
Batting Runs: 2
Batting Dismissal: c †Karthik b Smith Player Name: RA Jadeja
Batting Runs: 12
Batting Dismissal: run out (†Karthik/Johnson) Player Name: JA Morkel
Batting Runs: 0
Batting Dismissal: c Tendulkar b Malinga Player Name: WP Saha
Batting Runs: 5
Batting Dismissal: c †Karthik b Malinga Player Name: R Ashwin
Batting Runs: 13
Batting Dismissal: not out Player Name: BW Hilfenhaus
Batting Runs: 0
Batting Dismissal: not out Player Name: None
Batting Runs: 7
Batting Dismissal: (b 1, w 6) Player Name: None
Batting Runs: 173
Batting Dismissal: (8 wickets; 20 overs; 100 mins) In [46]:
Do you really want to exit ([y]/n)? y
liz@nb-liz:~$ exit
exit
Script done, file is pyquery.log2
liz@nb-liz:~$

【pyQuery分析实例】分析体育网冠军联盟比赛成绩的更多相关文章

  1. (转)实例分析:MySQL优化经验

    [IT专家网独家]同时在线访问量继续增大,对于1G内存的服务器明显感觉到吃力,严重时甚至每天都会死机,或者时不时的服务器卡一下,这个问题曾经困扰了我半个多月.MySQL使用是很具伸缩性的算法,因此你通 ...

  2. Mahout机器学习平台之聚类算法具体剖析(含实例分析)

    第一部分: 学习Mahout必需要知道的资料查找技能: 学会查官方帮助文档: 解压用于安装文件(mahout-distribution-0.6.tar.gz),找到例如以下位置.我将该文件解压到win ...

  3. 【Matplotlib】数据可视化实例分析

    数据可视化实例分析 作者:白宁超 2017年7月19日09:09:07 摘要:数据可视化主要旨在借助于图形化手段,清晰有效地传达与沟通信息.但是,这并不就意味着数据可视化就一定因为要实现其功能用途而令 ...

  4. 实例分析jdom和dom4j的使用和区别 (转)

    实例分析jdom和dom4j的使用和区别   对于xml的解析和生成,我们在实际应用中用的比较多的是JDOM和DOM4J,下面通过例子来分析两者的区别(在这里我就不详细讲解怎么具体解析xml,如果对于 ...

  5. RPC原理及RPC实例分析

    在学校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用下,如下所示.这些程序的特点是服务消费方和服务提供方是本地调用关系. 1 2 3 4 5 6 public class ...

  6. java基础学习05(面向对象基础01--类实例分析)

    面向对象基础01(类实例分析) 实现的目标 1.如何分析一个类(类的基本分析思路) 分析的思路 1.根据要求写出类所包含的属性2.所有的属性都必须进行封装(private)3.封装之后的属性通过set ...

  7. Oracle dbms_lock.sleep()存储过程使用技巧-场景-分析-实例

    <Oracle dbms_lock.sleep()存储过程使用技巧>-场景-分析-实例 摘要:今天是2014年3月10日,北京,雾霾,下午组织相关部门开会.会议的结尾一名开发工程师找到了我 ...

  8. sql注入实例分析

    什么是SQL注入攻击?引用百度百科的解释: sql注入_百度百科: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具 ...

  9. 实例分析ELF文件静态链接

    参考文献: <ELF V1.2> <程序员的自我修养---链接.装载与库>第4章 静态链接 开发平台: [thm@tanghuimin static_link]$ uname ...

随机推荐

  1. Python PIL ImageDraw 和ImageFont模块学习

    ImageDraw 新建一个空白图片为本文作示例,新建空白文件的方法 见Image模块,Image.new: import Image blank = Image.new("RGB" ...

  2. CodeMIrror 简单使用

    代码高亮是程序员的刚需,不管是在笔记类,论坛类,博客类web网站中,都对代码高亮提出要求,不高亮的代码阅读体验很差,codeMirror是一个前端代码高亮库,使用方便. codeMirror可以直接在 ...

  3. SQL Server 用SQL语句查找某个表的触发器

    select   *   from   sysobjects   where   xtype='TR'   and   parent_obj=object_id('表名') 再用sp_helptext ...

  4. Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable con

    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptab ...

  5. Maven-002-eclipse 插件安装及实例

    因为平常编码的时候,习惯了使用 eclipse 进行编码,因而需要将 eclipse 安装 maven 的插件,安装步骤如下所示: 一.安装 选择菜单: help -> Install New  ...

  6. 分布式服务框架dubbo原理解析 转

    alibaba有好几个分布式框架,主要有:进行远程调用(类似于RMI的这种远程调用)的(dubbo.hsf),jms消息服务(napoli.notify),KV数据库(tair)等.这个框架/工具/产 ...

  7. DBCC TRACEON/TRACEOFF/TRACESTATUS

    1. enable trace DBCC TRACEON ( trace# [ ,...n ][ , -1 ] ) [ WITH NO_INFOMSGS ] trace# Is the number ...

  8. convert Timestamp to Real time

    select r.ring_buffer_address, r.ring_buffer_type, dateadd (ms, r.[timestamp] - sysinfo.sqlserver_sta ...

  9. 微信支付开发(12) 认清微信支付v2和v3

    微信支付现在分为v2版和v3版 2014年9月10号之前申请的为v2版,之后申请的为v3版. V2版中的参数有AppIDAppSecret支付专用签名串PaySignKey商户号PartnerID初始 ...

  10. Vue.2.0.5-深入响应式原理

    大部分的基础内容我们已经讲到了,现在讲点底层内容.Vue 最显著的一个功能是响应系统 -- 模型只是普通对象,修改它则更新视图.这会让状态管理变得非常简单且直观,不过理解它的原理以避免一些常见的陷阱也 ...