from bs4 import BeautifulSoup
h = '<ul id="parameter2" class ="p-parameter-list"> <li title="ldz"> item name: ldzmm</li> <li title="bs/bs">gx: bs/bs</li> </ul>'
soup = BeautifulSoup(h, 'html.parser')
uls = soup.find_all('ul')
for ul in uls:
for li in ul.children:
if li.string.strip().startswith('gx:'):
print(li.string)
結果:
沒有使用到
re
, 既然使用了bs4
那就盡可能利用他的功能另外有個小建議, 問問題盡量貼上代碼, 不要使用截圖!
我回答過的問題: Python-QA