<dt><a name="313"></a>ADHE 313 (6) <b>Organization of Adult Basic Education Programs</b></dt>
想抓出ADHE313和Organization of Adult Basic Education Programs
想抓出ADHE313和Organization of Adult Basic Education Programs
|
asjMay 28, 2015
1
这难道不是应该用CSS/JQuery selector,或者XPath么?
|
|
2
<\/a>(.*)<b>(.*?)<\/b>
|
|
3
xpath比较简单 但是想学下正则的方法
|
|
shoumuMay 28, 2015
4
看一下pyquery吧,支持jQuery的语法
|
|
professorzMay 28, 2015
5
.+<\\/a>(.+)(6)<b>(.+)<\\/b>.+
java下的regex |
|
6
python的如何写
|
|
yiyiwaMay 28, 2015
7
python测试了一下,不完善,有空的东西。
'\>([^\<]*)\<' |
|
8
m=re.search("</a>(.*?)\s(",text)
print (m.group(1)) m=re.search("<b>(.*?)</b>(",text) print (m.group(1)) |
|
9
如果要取ADHE 313呢?
如何判断第二个空格?当然用字符串的search切片功能很容易达到,只是想知道正则如何达到 |
|
10
m=re.search("</a>(.*?)\s+\(",text)
print (m.group(1)) 当然方法比较笨,如果第二个空格后不是“(”就没办法了 |
|
asjMay 28, 2015
11
|
|
fyMay 28, 2015
12
这个需求不用正则,会简单得多
page.xpath("//dt/text()") -> ADHE 313 (6) page.xpath("//dt/b/text()") -> Organization of Adult Basic Education Programs |
|
picasso250May 28, 2015
13
/a>([\w ()]+)<b>([\w ]+)</b>
最简单的解决了你现在的问题。 |
|
picasso250May 28, 2015
14
对不起,上一个是错误的,多提取了(6)
/a>(\w+ \d+).+?<b>([\w ]+)</b> |
|
leozy2014May 28, 2015
15
print re.findall('</a>(.*?) \(6\) <b>(.*?)</b></dt>', s)
#[('ADHE 313', 'Organization of Adult Basic Education Programs')] |
|
wmttomMay 28, 2015
16
python正则 (?<=>)[\w, ,\(,\)]+?(?= \(|<)
re.findall("(?<=>)[\w, ,\(,\)]+?(?= \(|<)", '<dt><a name="313"></a>ADHE 313 (6) <b>Organization of Adult Basic Education Programs</b></dt>') ['ADHE 313', 'Organization of Adult Basic Education Programs'] |
|
17
楼上两个貌似都不能用
|
|
18
sorry这个可行
print re.findall('</a>(.*?) \(6\) <b>(.*?)</b></dt>', s) #[('ADHE 313', 'Organization of Adult Basic Education Programs')] |