正则与Xpath
正则如此简单:https://regexlearn.com/zh-cn/cheatsheet
搞清楚先行后行匹配即可
re.match与re.search的区别
re in python
re.match 只匹配字符串的开始,如果字符串开始不符合正则表达式,则匹配失败,函数返回 None,
re.search 匹配整个字符串,直到找到一个匹配
re.findall返回所有
Xpath:
xpather.com
Tip: 按着control可以生成匹配语法
| Signal | |
|---|---|
| / | root directory |
| // | all sub directory |
| [1] | the first dom of selected |
| /message/@name | attribute "name" of message |
| message[@name='bob'] | message with name equales 'bob' |
| message[text()='Alice'] | message with name |
| normalize-space() | |
| contains(A,B) | Whether A contains B |
| /message/parrent::node | Parent node of node 'message' |
| /message/child::node | Child node of node 'message' |