【发布时间】:2016-08-30 09:01:41
【问题描述】:
我正在尝试使用 BS4 解析站点中的 html 内容。我得到了我的 html 片段,但我需要删除所有标签类、ID、样式等。
例如:
<div class="applinks">
<div class="appbuttons">
<a href="https://geo.itunes.apple.com/ru/app/cloud-hub-file-manager-document/id972238010?mt=8&at=11l3Ss" rel="nofollow" target="_blank" title="Cloud Hub - File Manager, Document Reader, Clouds Browser and Download Manager">Загрузить</a>
<span onmouseout="jQuery('.wpappbox-8429dd98d1602dec9a9fc989204dbf7c .qrcode').hide();" onmouseover="jQuery('.wpappbox-8429dd98d1602dec9a9fc989204dbf7c .qrcode').show();">QR-Code</span>
</div>
</div>
我需要得到:
<div>
<div>
<a href="https://geo.itunes.apple.com/ru/app/cloud-hub-file-manager-document/id972238010?mt=8&at=11l3Ss" rel="nofollow" target="_blank" title="Cloud Hub - File Manager, Document Reader, Clouds Browser and Download Manager">Загрузить</a>
<span>QR-Code</span>
</div>
</div>
我的代码:
# coding: utf-8
import requests
from bs4 import BeautifulSoup
url = "https://lifehacker.ru/2016/08/29/app-store-29-august-2016/"
r = requests.get(url)
soup = BeautifulSoup(r.content)
post_content = soup.find("div", {"class","post-content"})
print post_content
我怎样才能删除所有标签属性?
【问题讨论】:
标签: python html web-scraping tags beautifulsoup