文章詳情頁
python - 把<dl></dl>標簽包含進去如何拿到我想要的內容
瀏覽:83日期:2022-07-21 08:07:19
問題描述
1.我把<dl>標簽加進去拿到的是空內容,我該怎么寫匹配規則,不加<dl>標簽倒是可以拿到想要的內容2.問題代碼
pattern = re.compile(r’<dl>.*?<dd><a href='http://www.cgvv.com.cn/wenda/(.*?)'>(.*?)</a></dd>.*?</dl>’)
3.不把<dl>標簽加進去可以拿到想要的內容
4.附上網頁源代碼
<dl><dt>《明末工程師》正文</dt><dd><a href='http://www.cgvv.com.cn/book/1440/xx'>第一章 穿越后的窘境</a></dd></dl>
問題解答
回答1:# 你可能需要加個模式# re.S 使 . 匹配包括換行在內的所有字符pattern = re.compile(r’<dl>.*?<dd><a href='http://www.cgvv.com.cn/wenda/(.*?)'>(.*?)</a></dd>.*?</dl>’, re.S)print re.findall(pattern, a)回答2:
// /需要轉義下<dl>.*?<dd><a href='http://www.cgvv.com.cn/wenda/(.*?)'>(.*?)</a></dd>.*?</dl>
相關文章:
1. mysql - 這種分級一對多,且分級不平衡的模型該怎么設計表?2. javascript - vue-cli npm run build編譯報錯3. python - Scrapy ItemLoader數據清洗疑問4. PHP類屬性聲明?5. javascript - Object.define 可以監聽object變化,那基本類型變量如何監聽6. css - div外層有一圈白色7. atom開始輸入!然后按tab只有空格出現沒有html格式出現8. javascript - js setTimeout在雙重for循環中如何使用?9. python - pip install出現下面圖中的報錯 什么原因?10. javascript - vue 2.0 :key的作用
排行榜
