下面一段html代码怎么用Python+正则一次性提取出来:标题,url,时间,简介组成一个字典?



 <div class="list_item clearfix">
        <div class="item_top">
            <h2><a href="http://money.163.com/15/0902/09/B2GEL9V8002551G6.html">主营业务负增长 董明珠还自信?</a></h2>
                            <a href="http://money.163.com/15/0902/09/B2GEL9V8002551G6.html" title="主营业务负增长 董明珠还自信?" class="newsimg" lang="http://img1.cache.netease.com/stock/2015/9/2/2015090209124874ceb_550.jpg"><img src="http://s.cimg.163.com/stock/2015/9/2/2015090209124874ceb_550.jpg.119x83.jpg" alt="主营业务负增长 董明珠还自信?" /></a>                                <p>[摘要:8月30日晚间公布的格力电器上半年财报无疑给董明珠浇了一盆冷水。虽然董明珠嘴上仍在硬撑,但她的底气明显不足了。因为,格力的主营业务——空调出问题了。当格力开始不谈承诺的时候,董明珠最应该干的事,是静下心来好好反思,而不是把更多的心思花在无聊的口水战和吹牛逼 ...<br />
                <span class="time">2015-09-02 09:20:55</span>
            </p>
        </div>
        <div class="item_bottom">
            <ul class="mod_list">
                <li>董明珠应该静下心好好反思,而不是把心思花在口水战和吹牛逼上。</li>                                                            <li><a href="http://money.163.com/15/0902/09/B2GEL9V8002551G6.html">主营业务负增长 董明珠还自信?</a></li>                </ul>
        </div>
    </div>
                       <div class="list_item clearfix">
        <div class="item_top">
            <h2><a href="http://money.163.com/15/0831/11/B2BGVVQ0002551G6.html">中国手机的非洲历险记</a></h2>
                            <a href="http://money.163.com/15/0831/11/B2BGVVQ0002551G6.html" title="中国手机的非洲历险记" class="newsimg" lang="http://img4.cache.netease.com/stock/2015/8/31/201508311110060cc03.jpg"><img src="http://s.cimg.163.com/stock/2015/8/31/201508311110060cc03.jpg.119x83.jpg" alt="中国手机的非洲历险记" /></a>                                <p>[摘要:中国手机全球化版图扩张中,已经完成了两个阶段,国内市场红海一片,几乎没有太多眷恋;欧美发达国家,市场如堡垒般稳固,而且面临专利、渠道等麻烦,败走麦城似乎是命中注定的事儿。]原标题:[亦观察] No.616 中国手机的非洲历险记如今,中国手机正悄然转移重点,把  ...<br />
                <span class="time">2015-08-31 11:25:30</span>
            </p>
        </div>

python 正则表达式 HTML

无聊数太阳 10 years, 10 months ago

建议使用 beautifulsoup 库解析,和前端操作dom类似解析html

想不到啥好名 answered 10 years, 10 months ago

好像用 Python 的库直接解析 HTML 更简单

不来方·夕莉 answered 10 years, 10 months ago

Your Answer