【pyQuery分析实例】分析体育网冠军联盟比赛成绩
目标地址: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分析实例】分析体育网冠军联盟比赛成绩的更多相关文章
- (转)实例分析:MySQL优化经验
[IT专家网独家]同时在线访问量继续增大,对于1G内存的服务器明显感觉到吃力,严重时甚至每天都会死机,或者时不时的服务器卡一下,这个问题曾经困扰了我半个多月.MySQL使用是很具伸缩性的算法,因此你通 ...
- Mahout机器学习平台之聚类算法具体剖析(含实例分析)
第一部分: 学习Mahout必需要知道的资料查找技能: 学会查官方帮助文档: 解压用于安装文件(mahout-distribution-0.6.tar.gz),找到例如以下位置.我将该文件解压到win ...
- 【Matplotlib】数据可视化实例分析
数据可视化实例分析 作者:白宁超 2017年7月19日09:09:07 摘要:数据可视化主要旨在借助于图形化手段,清晰有效地传达与沟通信息.但是,这并不就意味着数据可视化就一定因为要实现其功能用途而令 ...
- 实例分析jdom和dom4j的使用和区别 (转)
实例分析jdom和dom4j的使用和区别 对于xml的解析和生成,我们在实际应用中用的比较多的是JDOM和DOM4J,下面通过例子来分析两者的区别(在这里我就不详细讲解怎么具体解析xml,如果对于 ...
- RPC原理及RPC实例分析
在学校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用下,如下所示.这些程序的特点是服务消费方和服务提供方是本地调用关系. 1 2 3 4 5 6 public class ...
- java基础学习05(面向对象基础01--类实例分析)
面向对象基础01(类实例分析) 实现的目标 1.如何分析一个类(类的基本分析思路) 分析的思路 1.根据要求写出类所包含的属性2.所有的属性都必须进行封装(private)3.封装之后的属性通过set ...
- Oracle dbms_lock.sleep()存储过程使用技巧-场景-分析-实例
<Oracle dbms_lock.sleep()存储过程使用技巧>-场景-分析-实例 摘要:今天是2014年3月10日,北京,雾霾,下午组织相关部门开会.会议的结尾一名开发工程师找到了我 ...
- sql注入实例分析
什么是SQL注入攻击?引用百度百科的解释: sql注入_百度百科: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具 ...
- 实例分析ELF文件静态链接
参考文献: <ELF V1.2> <程序员的自我修养---链接.装载与库>第4章 静态链接 开发平台: [thm@tanghuimin static_link]$ uname ...
随机推荐
- Selenium2学习-028-WebUI自动化实战实例-026-获取页面元素值或者元素属性值
在自动化脚本编写过程中,经常需要获取页面元素的文本进行判断,以便对于不同的文本进行不同的处理.比如:很多的购物网站,加入购物车的按钮是有多个状态的(加入购物车.到货通知.暂不销售等),那么在实际的操作 ...
- offset/client/scroll一些总结
offset/client/scroll一些总结 1.offset 首先offset共有五个值 1.offsetParent 2.offsetTop 3.offsetLeft 4.offsetWidt ...
- iOS 并发编程之 Operation Queues
现如今移动设备也早已经进入了多核心 CPU 时代,并且随着时间的推移,CPU 的核心数只会增加不会减少.而作为软件开发者,我们需要做的就是尽可能地提高应用的并发性,来充分利用这些多核心 CPU 的性能 ...
- python3学习问题汇总
1.python2脚本转python3报类型错误 TypeError: ‘str’ does not support the buffer interface 原因:Python3x的string类型 ...
- 如何查看lib文件的导出函数
参考:http://blog.csdn.net/brioxu/article/details/6932350 dumpbin /exports /out:xxx.dmp xxx.lib
- 安装和删除 Alcatraz 插件
在终端下输入如下命令来安装Alcatraz: curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/install. ...
- subprocess使用
1. Popen使用 test = subprocess.Popen('ls /tmpa', shell=True, stdout = subprocess.PIPE, stderr=subproce ...
- [gerrit] Auto Add Reviewer When Push Code
1. ${PROJECT_ROOT}/.git/config 加入如下代码 [remote "review"] url = ssh://${username}@codeserver ...
- 头部固定下面滑动&&获取手机屏高
height(){ //获取屏高 let phone_height = document.documentElement.clientHeight; let group = this.refs.sea ...
- PAT 解题报告 1049. Counting Ones (30)
1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...