目标提取内容在网页的()中,re正则需要怎么来写能匹配到?,提取re, <dt>
目标提取内容在网页的()中,re正则需要怎么来写能匹配到?,提取re,
<dt> <span class="gray6 ">名称:</span> <a title="查看" class="blue" id="agantesfxq_B02_08" href="http://xiandai007.com/esf/" target="_blank">安现</a> ( <a class="blue" id="agatdesf_B02_09" href="/ho-a021551/" target="_blank"> 中间 </a><a class="blue" id="agatdesf_B02_10" href="/ho-a011551-b03497/" target="_blank"> 草原牧场 #这是我要抓取的内容我把它放到组(.*?)里面。 </a> ) [ <a class="blue" id="agantdesf_B02_11" href="acchor">图文</a> ] </dt>
我就是想抓取第9行那里的中文内容,放到一个组里面。本来应该很简单,但是试了好多次就是抓不到,报错是没有内容。估计和第5行,和11行的括号有关。请问怎么写正则才能抓得到?
我原来这样写
d = re.search(r'<a class="blue" id="agatdesf_B02_10".*?>\s*(.*?)\s*</a>', s).group(1)
抓不到,谁帮我看下错在哪里?
推荐一本书 精通正则表达式 看看就都会了!
python3
html=''' <dt> <span class="gray6 ">名称:</span> <a title="查看" class="blue" id="agantesfxq_B02_08" href="http://xiandai007.com/esf/" target="_blank">安现</a> ( <a class="blue" id="agatdesf_B02_09" href="/ho-a021551/" target="_blank"> 中间 </a><a class="blue" id="agatdesf_B02_10" href="/ho-a011551-b03497/" target="_blank"> 草原牧场 #这是我要抓取的内容我把它放到组(.*?)里面。 </a> ) [ <a class="blue" id="agantdesf_B02_11" href="acchor">图文</a> ] </dt>'''import rep=re.compile(r'<a\s+?[^>]*?id="agatdesf_B02_10"[^>]*>([^<]*)</a>')print(p.findall(html)[0].strip())##草原牧场 #这是我要抓取的内容我把它放到组(.*?)里面。
编橙之家文章,
相关内容
- wxPython与pyQt4在客户端哪种更有优势,wxpythonpyqt4更有,本
- Python里面模拟登陆Weibo Element is not currently interactable,
- 求问Ubuntu下eclipse+pydev环境提示有错,ubuntupydev,程序源码
- Python列表转换怎么写比较高效,python列表怎么写,a = [
- 请问python什么方法可以找到当前目录下的指定文件?,
- Python写文件时换行没执行哪里出问题,python写换行执行
- python批量抓取二级域名标题的方法,python二级域名,#
- Linux实现Python读取word文件方法是?,linuxpython,R.T.doc 是
- Python os.environ能获取到的环境变量,在os.environ.getenv得不
- Python lxml xpath解析为何只能获得头部信息,lxmlxpath,我在
评论关闭