文章詳情頁
python - 把<dl></dl>標簽包含進去如何拿到我想要的內容
瀏覽:128日期:2022-07-21 08:07:19
問題描述
1.我把<dl>標簽加進去拿到的是空內容,我該怎么寫匹配規則,不加<dl>標簽倒是可以拿到想要的內容2.問題代碼
pattern = re.compile(r’<dl>.*?<dd><a href='http://m.propowerdrill.cn/wenda/(.*?)'>(.*?)</a></dd>.*?</dl>’)
3.不把<dl>標簽加進去可以拿到想要的內容
4.附上網頁源代碼
<dl><dt>《明末工程師》正文</dt><dd><a href='http://m.propowerdrill.cn/book/1440/xx'>第一章 穿越后的窘境</a></dd></dl>
問題解答
回答1:# 你可能需要加個模式# re.S 使 . 匹配包括換行在內的所有字符pattern = re.compile(r’<dl>.*?<dd><a href='http://m.propowerdrill.cn/wenda/(.*?)'>(.*?)</a></dd>.*?</dl>’, re.S)print re.findall(pattern, a)回答2:
// /需要轉義下<dl>.*?<dd><a href='http://m.propowerdrill.cn/wenda/(.*?)'>(.*?)</a></dd>.*?</dl>
相關文章:
1. 請教一條mysql的sql語句寫法;2. javascript - react+百度地圖3. angular.js - 關于angular react vue 我們在什么實際的開發項目中使用?如何選擇?4. html5 - iOS的webview加載出來的H5網頁,怎么修改html標簽select的樣式字體?5. vue.js - vue+webpack+vue-router 部署到nginx服務器下,非根目錄,前后端怎樣配置文件?6. javascript - 為什么當index等于5的時候,不在當前頁面跳轉到百度?不跳轉的代碼在倒數第五行7. 手動啟動mysql服務出錯,1067錯誤,如何解決呢?8. 這是什么情況???9. index.php錯誤,求指點10. 跟著課件一模一樣的操作使用tp6,出現了錯誤
排行榜
