Dưới đây là những gì tôi có cho đến nay:Hủy bỏ tất cả các phong cách, kịch bản, và các thẻ html từ một trang html
from bs4 import BeautifulSoup
def cleanme(html):
soup = BeautifulSoup(html) # create a new bs4 object from the html data loaded
for script in soup(["script"]):
script.extract()
text = soup.get_text()
return text
testhtml = "<!DOCTYPE HTML>\n<head>\n<title>THIS IS AN EXAMPLE </title><style>.call {font-family:Arial;}</style><script>getit</script><body>I need this text captured<h1>And this</h1></body>"
cleaned = cleanme(testhtml)
print (cleaned)
này đang nỗ lực để loại bỏ các script
kết quả mong muốn của bạn là gì? –