使用beautifulsoup和python删除某些标记
问题 我正在尝试从我的html文件中删除样式标记,如使用beautifulsoup和python删除某些标记,python,html,beautifulsoup,strip,Python,Html,Beautifulsoup,Strip,问题 我正在尝试从我的html文件中删除样式标记,如和,该文件由BeautifulSoup下载。我确实希望保留标记包含的内容(如文本) 然而,这似乎不起作用 我尝试过的 for url in urls: response = requests.get(url, headers=headers) soup = BeautifulSoup(response.content, 'html.parser') table = soup.find("div", {"class": "
和
,该文件由BeautifulSoup下载。我确实希望保留标记包含的内容(如文本)
然而,这似乎不起作用
我尝试过的
for url in urls:
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
table = soup.find("div", {"class": "product_specifications bottom_l js_readmore_content"})
print "<hr style='border-width:5px;'>"
for style in table.find_all('style'):
if 'style' in style.attrs:
del style.attrs['style']
print table
对于url中的url:
response=requests.get(url,headers=headers)
soup=BeautifulSoup(response.content'html.parser')
table=soup.find(“div”,“class”:“产品规格底部”\u l js\u readmore\u内容”})
打印“
我尝试使用的URL
您可以使用
分解()
:
如果只想清除文本或从树中删除元素,请使用clear
和extract
(上面的描述就是分解)。您正在查找unwrap()
您的\u soup.tag.unwrap()您尚未解释当前解决方案的问题所在。该解决方案从原始页面开始仍为样式。我仍需要保留其内容。我只想删除标签本身。因为它是我的文件的样式,我不想这样做,所以请在问题中解释它,而不是我的评论