[英]extracting text from html div tag using python and bs4
<div class="available-date-component">Available 4/1 at 9:00 AM</div>
我正在嘗試使用下面的代碼從上面的 html div 中提取文本
date = page.find('div', {'class' : 'available-date-component'})
print(date.string) # this line needs to be fixed
有沒有人對我如何只能打印“4/1 上午 9:00 可用”而不是整個 div 有任何建議?
def clean(raw_html):
cleaner = re.compile('<.*?>')
cleantext = re.sub(cleaner, '', raw_html)
return cleantext
我最終通過這個 function 傳遞了 html div,它刪除了所有標簽並留下了我想要的文本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.