[D]python正则表达式求助

dweqd 2012-03-08 07:34:14
<a onmousedown="return JSlog({'l':3,'id':20145,'u':this.href,'ps':1})" href="http://www.ems.com.cn/" target="_blank">中国邮政速递物流</a>



<a onmousedown="return JSlog({'l':3,'id':20145,'u':this.href,'ps':1})" href=" http://www.ems.com.cn/" target="_blank">中国邮政速递物流</a>
在这段怎么提取 url
和 中国邮政速递物流


---------------------
Double行动:
原帖分数:20
加分:20
...全文
120 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zimingtjb 2012-03-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 agoago_2009 的回复:]

Python code
import re

string = ''' <a onmousedown="return JSlog({'l':3,'id':20145,'u':this.href,'ps':1})" href="http://www.ems.com.cn/" target="_blank">中国邮政速递物流</a> '''
print '原始字符串:' , string

pat……
[/Quote]
这段就可以了
iEverX 2012-03-08
  • 打赏
  • 举报
回复
自己稍微学习一下,很简单的
Gloveing 2012-03-08
  • 打赏
  • 举报
回复
import re

string = ''' <a onmousedown="return JSlog({'l':3,'id':20145,'u':this.href,'ps':1})" href="http://www.ems.com.cn/" target="_blank">中国邮政速递物流</a> '''
print '原始字符串:' , string

pattern = 'http://\w+\..+?/'
print 'URL: ' , re.findall(pattern,string)[0]

pattern = '>.+?</a>'
print 'name: ' , re.findall(pattern,string)[0][1:-4]

JoeBlackzqq 2012-03-08
  • 打赏
  • 举报
回复
href="(.*?)".*?>(.*?)<

()内的就是你要的!

37,718

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧