0
私はDjangoテンプレートのHTMLテーブルとしてhtmlテーブルを持つ変数を渡そうとしています。Djangoテンプレートは、安全なまたはautoescapeを使用するかどうかにかかわらずhtmlテーブルを削除しています
私はそれを渡して|安全にするか、自動エスケープをオフにします。すべてのHTMLは挿入されていますが、テーブルは完全に削除されています。
import urllib.request
from bs4 import BeautifulSoup
tt_opener = urllib.request.build_opener()
tt_opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
tt_service = tt_opener.open('https://managed.mytalktalkbusiness.co.uk/network-status/')
tt_soup = BeautifulSoup(tt_service, "html.parser")
tt_data = tt_soup.table
テンプレート
<div id="TALK-TALK-Service" style="width:50vw; height:50vw; float:left;">
{{ TalkTalk |kksafe }}
</div>
シェル経由で印刷tt_data変数
<table border="0" cellpadding="0" cellspacing="0" class="opaltable" width="100%"><th nowrap="nowrap"> </th><th nowrap="nowrap">Issue</th><th nowrap="nowrap">Services affected</th><th nowrap="nowrap">Location</th><th nowrap="nowrap">Last update</th><tr><td width="20"><img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif"/></td><td width="350"><a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15462">incident 10574541 - Washington Exchange - no service</a></td><td>Extranet, Ethernet, EoFTTC & EFM via TalkTalk, DSL via TalkTalk</td><td width="100">n/a</td><td nowrap="nowrap" width="150">11th Oct 2017 12:53</td></tr><tr><td width="20"><img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif"/></td><td width="350"><a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15448">Incident 10573277 - Network – P1 – Some TTB customers are experiencing Post Dial Delay SIP/VOE</a></td><td>SIP/VOE</td><td width="100">n/a</td><td nowrap="nowrap" width="150">11th Oct 2017 12:27</td></tr></table>
HTMLはあなたのtt_soup
変数があるWebページ
<div id="TALK-TALK-Service" style="width:50vw; height:50vw; float:left;">
[ , Issue, Services affected, Location, Last update, <img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif"><a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15462">incident 10574541 - Washington Exchange - no service</a>Extranet, Ethernet, EoFTTC & EFM via TalkTalk, DSL via TalkTalkn/a11th Oct 2017 12:53, <img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif">, <img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif">, <a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15462">incident 10574541 - Washington Exchange - no service</a>, <a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15462">incident 10574541 - Washington Exchange - no service</a>, Extranet, Ethernet, EoFTTC & EFM via TalkTalk, DSL via TalkTalk, n/a, 11th Oct 2017 12:53, <img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif"><a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15448">Incident 10573277 - Network – P1 – Some TTB customers are experiencing Post Dial Delay SIP/VOE</a>SIP/VOEn/a11th Oct 2017 12:27, <img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif">, <img src="https://managed.mytalktalkbusiness.co.uk/images/redlight.gif">, <a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15448">Incident 10573277 - Network – P1 – Some TTB customers are experiencing Post Dial Delay SIP/VOE</a>, <a href="https://managed.mytalktalkbusiness.co.uk/network-status-report.php?reportid=15448">Incident 10573277 - Network – P1 – Some TTB customers are experiencing Post Dial Delay SIP/VOE</a>, SIP/VOE, n/a, 11th Oct 2017 12:27]
</div>
ありがとうございました – AlexW