免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: qingyuan0o0
打印 上一主题 下一主题

[文本处理] 关于XML和HTML的提取值的请教 [复制链接]

论坛徽章:
9
2015亚冠之阿尔纳斯尔
日期:2015-09-10 16:21:162015亚冠之塔什干火车头
日期:2015-07-01 16:23:022015年亚洲杯之巴勒斯坦
日期:2015-04-20 17:19:46子鼠
日期:2014-11-13 09:51:26未羊
日期:2014-08-28 18:13:36技术图书徽章
日期:2014-02-21 09:30:15酉鸡
日期:2014-01-14 11:12:49天蝎座
日期:2013-12-09 17:56:53平安夜徽章
日期:2015-12-26 00:06:30
11 [报告]
发表于 2013-09-26 11:16 |只看该作者
  1. #!/usr/bin/env python
  2. from BeautifulSoup import BeautifulSoup
  3. text=open("txt").read()
  4. soup=BeautifulSoup(''.join(text))
  5. print soup('postfield',{"name":"csrfToken"})[0]['value']
复制代码

论坛徽章:
0
12
发表于 2013-09-26 11:30
回复 5# LikeLx


    不会的,我用有修改过,就是有个问题
  1. <img src="/im/images/userstatus/pc.gif" alt="."></img><a href="/im/chat/toinputMsg.action?touserid=123451047&amp;type=all">...</a>&nbsp;<a href="/im/chat/toinputMsg.action?touserid=123451047&amp;type=all">和TA聊</a>&nbsp;<anchor>打招呼<go method="post" href="/im/chat/greet.action"><postfield name="toUsers" value="=xxxxxxxxxxxxxxxxxDyqZKOm8eehDaepxxxxxxxxxxxxxxxN"/></go></anchor><br/>
复制代码
我在获取touserid的值的时候会出现2个我要怎么只取一个呢?,代码判定是其中一个<a href=有</img>
但是我touserid=`grep -Eo  '</img><a href="/im/chat/toinputMsg.action(.*?)' ${TempDir}/searchOtherInfoList.action | grep -Eo  'touserid=\w+'`
这么取值还是出现了2个
touserid=123451047 touserid=123451047
求助

论坛徽章:
0
13 [报告]
发表于 2013-09-26 11:31 |只看该作者
回复 11# HH106


    我想说的是路由器系统太小,没有安装python

论坛徽章:
14
15-16赛季CBA联赛之辽宁
日期:2019-06-16 15:47:3515-16赛季CBA联赛之广夏
日期:2016-08-13 21:24:352015亚冠之武里南联
日期:2015-07-07 17:37:372015亚冠之萨济拖拉机
日期:2015-07-06 17:07:482015亚冠之全北现代
日期:2015-06-04 13:54:272015亚冠之城南
日期:2015-05-21 15:43:212015年亚洲杯之伊朗
日期:2015-04-25 18:20:362015年亚洲杯之伊朗
日期:2015-04-20 16:06:052015年亚洲杯之科威特
日期:2015-03-07 12:51:26丑牛
日期:2014-12-30 10:26:38申猴
日期:2014-09-28 22:40:18金牛座
日期:2014-09-13 21:12:22
14 [报告]
发表于 2013-09-26 11:34 |只看该作者
回复 12# qingyuan0o0


    grep -Eo  '</img><a href="/im/chat/toinputMsg.action(.*?)' c.txt |sed  -r 's/.*touserid=([0-9]+).*/\1/'

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
15 [报告]
发表于 2013-09-26 11:38 |只看该作者
  1. sed -r '/touserid/!d; s/.*touserid=([0-9]+).*/\1/' urfile
复制代码

论坛徽章:
14
15-16赛季CBA联赛之辽宁
日期:2019-06-16 15:47:3515-16赛季CBA联赛之广夏
日期:2016-08-13 21:24:352015亚冠之武里南联
日期:2015-07-07 17:37:372015亚冠之萨济拖拉机
日期:2015-07-06 17:07:482015亚冠之全北现代
日期:2015-06-04 13:54:272015亚冠之城南
日期:2015-05-21 15:43:212015年亚洲杯之伊朗
日期:2015-04-25 18:20:362015年亚洲杯之伊朗
日期:2015-04-20 16:06:052015年亚洲杯之科威特
日期:2015-03-07 12:51:26丑牛
日期:2014-12-30 10:26:38申猴
日期:2014-09-28 22:40:18金牛座
日期:2014-09-13 21:12:22
16 [报告]
发表于 2013-09-26 11:40 |只看该作者
回复 15# Shell_HAT


    拜大神

论坛徽章:
0
17 [报告]
发表于 2013-09-26 13:20 |只看该作者
本帖最后由 qingyuan0o0 于 2013-09-26 16:06 编辑

按照大神在第一页说的
  1. <a href="/im/user/userinfoByuserid.action?touserid=123451047&amp;t=1380172127438">缘</a>[在线]&gt;<a href="/im/index/recentcontacts.action?touserid=123451047">换人</a><br/> [新]测试1[13:08]<br/> [新]测试2[13:08]<br/><input name="msg1380172127371" title="" value="" type="text" emptyok="true" maxlength="1000"/><br/><anchor>发送消息 <go method="post" href="/im/chat/sendMsg.action?touserid=123451047" accept-charset="utf-8"><postfield name="backUrl" value=""/><postfield name="touchTitle" value=""/><postfield name="touchTextLength" value=""/><postfield name="msg" value="$(msg1380172127371)"/><postfield name="csrfToken" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/></go></anchor><br/> 添加&gt;<anchor>表情<go method="post" href="/im/chat/insertPic.action?touserid=123451047" accept-charset="utf-8"><postfield name="backUrl" value=""/><postfield name="touchTitle" value=""/><postfield name="touchTextLength" value=""/><postfield name="msg" value="$(msg1380172127371)"/></go></anchor>.<anchor>动作<go method="post" href="/im/chat/insertTouch.action?touserid=123451047" accept-charset="utf-8"><postfield name="backUrl" value=""/><postfield name="msg" value="$(msg1380172127371)"/></go></anchor>.<anchor>招呼<go method="post" href="/im/chat/sayHelloToFriend.action?touserid=123451047&amp;backUrl=" accept-charset="utf-8"></go></anchor><br/> ------------<br/> [13:06] 缘:测试<anchor>转<go method="post" href="/im/sayHello/sayHelloChooseFriendsByAll.action"><postfield name="type" value="all"/><postfield name="sayHelloText" value="测试"/><postfield name="fromSelect" value="fromSelectAll"/><postfield name="selectType" value="all"/></go></anchor><br/> [12:52] 我:hh<anchor>转<go method="post" href="/im/sayHello/sayHelloChooseFriendsByAll.action"><postfield name="type" value="all"/><postfield name="sayHelloText" value="hh"/><postfield name="fromSelect" value="fromSelectAll"/><postfield name="selectType" value="all"/></go></anchor><br/> (共1页)
复制代码
页面接收到消息会有提示一个[新]和后面的[13:08]时间,再一次刷新,就会变成下面的[13:06]对方用户名:内容到下面来了<anchor>转

而用'/新/!d 就变成包含新的行不删除,但是在wget下来后,所有内容就只是在第一行,并没有换行我应该怎么,一字不漏的把它记录下来,然后15秒后再刷新?

提取类似的这3部分,一个是,然后是按照时间先后顺序[13:08]排序内容测试1
[13:08] :测试1
[13:09] :测试2
每次内容变动后就按照时间递增

更新到第一页去了

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
18 [报告]
发表于 2013-09-26 13:34 |只看该作者
回复 17# qingyuan0o0


    以这段数据为例,你希望得到的结果是什么?

论坛徽章:
0
19 [报告]
发表于 2013-09-26 13:39 |只看该作者
本帖最后由 qingyuan0o0 于 2013-09-26 13:53 编辑

回复 18# Shell_HAT


    我希望得到的结果是每次刷新后有[新]测试1[13:08] 然后提取出来值(测试1)能保存到log文件中持续增长
info=`sed -r '/新/!d; s/.*[新]" :"([^"]+)".*/\1/' urfile`

echo info >> log
log:

[13:08] 测试1
[13:09] 测试2
...
..
.
总之就类似由下而上这样提取

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
20 [报告]
发表于 2013-09-26 13:57 |只看该作者
回复 19# qingyuan0o0
  1. sed 's/\[新\]/\n&/g' urfile | sed '/\[新\]/!d; s/.*新.\([^[]\+\)\(...:...\).*/\2 \1/g'
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP