如下:
<!-- <span class="flag">體驗新模版</span> -->
如果我們需要提取<!-- -->中的內容,通過BeautifulSoup方法會直接忽略<!-- -->中的內容
這時我們可以對網頁源碼作替換處理,將<!-- 字符串全部替換成空
res3 = requests.get(url,headers=headers,timeout=(10,60)).content
html1 = res3
html =eval(repr(html1 ).replace('<!-- ', '')) #此句爲替換源碼中網頁註釋部分
soup = BeautifulSoup(html, 'html.parser')
這樣通過BeautifulSoup方法去查找 span class="flag"