更新后在QWebFrame中截断html代码

时间:2014-10-15 22:06:58

标签: html c++ qt parsing qtwebkit

我使用 QT 5.3.1 32位,但我决定将我的QT更新为 5.3.2和64 BIT

我在解析HTML代码方面遇到了麻烦。

我的代码正在处理32位和5.3.1

std::string html = std::move(output.buffer); // html from curl - all ok
QWebPage * tmp_webpage = new QWebPage();
tmp_webpage->mainFrame()->setHtml(QString::fromStdString(html));
std::fstream test_stream;
test_stream.open("example14.html", std::ios::out | std::ios::in);
test_stream << tmp_webpage->mainFrame()->toHtml().toStdString(); // html is cut in about 50%
test_stream.close();

QWebFrame * tmp_frame = tmp_webpage->mainFrame();
QWebElement mainTable_site = tmp_frame->findFirstElement(QString::fromStdString(mainTable_selector)); // not found because qt cut my correct html

此代码正常运行,但现在我的HTML代码已放入QWebFrame中。

在此代码中 - &#34; test_stream&#34;采取预期的HTML代码

QByteArray html = std::move(output.buffer);
test_stream.write(html);

Html代码在</script>之后被删除。 附加了QWebFrame(最后 - </script>之后)</div></div></body></html>(当然原始代码是其他代码)

</script>之后,在原始的html代码中,我<table id="production_table" >而非</div></div></body></html>

问题:

  1. 如何设置setHtml()不会截断我的HTML代码? (我使用qt来解析一些html文件,我真的不想要新的类(比如tidyhtml)并再次编写代码 - 所有这些都是okey但是在之前的版本中)
  2. 原始HTML代码:

        <!DOCTYPE HTML>
    <html>
    <head>
        <title>O rety rety atakują ci z Bety ! (412|412) - Plemiona - Świat 80</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="apple-itunes-app" content="app-id=435365767, app-argument=x-sfp:///visit/tribal-wars">
        <link rel="apple-touch-icon-precomposed" href="/apple-icon-iphone-precomposed.png" />
        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-icon-ipad-precomposed.png" />
        <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-icon-iphone4-precomposed.png" />
        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-icon-retina-precomposed.png" />
        <link rel="stylesheet" type="text/css" href="/merged/mobile.css?1412598051" />
    
            <link rel="stylesheet" type="text/css" href="/css/game/overview_base.css?1412598051" />
    
    
        <script type="text/javascript" src="/merged/mobile.js?1412598051"></script>
    
            <script type="text/javascript" src="/js/game/upgrade_building.js?1408412983"></script>
    
    
    
        <script type="text/javascript">
        //<![CDATA[
            var image_base = "http://cdn.tribalwars.net/graphic/";
            var mobile = true;
            var mobiledevice = false;
            var game_data = {"player":{"name":"as2d99","ally":"4317","sitter":"0","sleep_start":"0","sitter_type":"normal","sleep_end":"0","sleep_last":"0","interstitial":"0","email_valid":"1","villages":"2","incomings":"0","supports":0,"knight_location":null,"knight_unit":null,"rank":2263,"points":"13019","date_started":"1391362221","is_guest":"0","id":"698410832","quest_progress":"0","premium":false,"account_manager":false,"farm_manager":false,"points_formatted":"13<span class=\"grey\">.<\/span>019","rank_formatted":"2<span class=\"grey\">.<\/span>263","pp":"0","new_ally_application":"0","new_ally_invite":"0","new_buddy_request":"0","new_forum_post":"127","new_igm":"0","new_items":"0","new_report":"0","fire_pixel":"0","new_quest":"1"},"village":{"id":96311,"name":"O rety rety atakuj\u0105 ci z Bety !","wood_prod":0.86666667626364,"stone_prod":0.86666667626364,"iron_prod":0.86666667626364,"storage_max":"400000","pop_max":"24960","wood_float":"400000","stone_float":"400000","iron_float":"400000","wood":400000,"stone":400000,"iron":400000,"pop":"23354","x":"412","y":"412","trader_away":"0","bonus_id":"8","bonus":{"wood":1.3,"stone":1.3,"iron":1.3},"buildings":{"village":"96311","main":"20","farm":"30","storage":"30","place":"1","barracks":"25","church":"1","church_f":"0","smith":"20","wood":"30","stone":"30","iron":"30","market":"20","stable":"20","wall":"20","garage":"15","hide":"10","snob":"1","statue":"1","watchtower":"0"},"player_id":"698410832","res":[400000,0.86666667626364,400000,0.86666667626364,400000,0.86666667626364,"400000","23354","24960"],"coord":"412|412"},"nav":{"parent":2},"link_base":"\/game.php?village=96311&amp;screen=","link_base_pure":"\/game.php?village=96311&screen=","csrf":"d199","world":"pl80","market":"pl","RTL":false,"version":"22314 8.27.1","majorVersion":"8.27.1","screen":"overview_villages","mode":null,"device":"desktop"};
            var csrf_token = 'd199';
            var server_utc_diff = 7200;
    
            var VillageContext = (!VillageContext) ? { } : VillageContext;
            VillageContext.claim_enabled = true;
        //]]>
        </script>
    </head>
    <body id="ds_body" class="mds">
    
    
    <div id="mNotifyContainer">
        <div id="notify_incomings" class="mNotify" style="display: none">
            <a href="#" class="mNotifyIcon mNotifyIconAttack"></a>
            <span class="mNotifyNumber">
                    0
                    </span>
        </div>
        <div id="notify_supports" class="mNotify" style="display: none">
            <a href="" class="mNotifyIcon mNotifyIconSupport"></a>
            <span class="mNotifyNumber"><a class="mNotifyNumber" href="""></a></span>
        </div>
        <div id="notify_mail" class="mNotify" style="display: none">
            <a href="/game.php?village=96311&amp;screen=mail" class="mNotifyIcon mNotifyIconMail"></a>
        </div>
        <div id="notify_report" class="mNotify" style="display: none">
            <a href="/game.php?village=96311&amp;screen=report" class="mNotifyIcon mNotifyIconReport"></a>
        </div>
        <div id="notify_forum" class="mNotify" >
            <a href="/game.php?village=96311&amp;mode=forum&amp;screen=ally" class="mNotifyIcon mNotifyIconAlly"></a>
        </div>
        <div class="mNotify" style="display: none">
            <a href="/game.php?village=96311&amp;screen=inventory" class="mNotifyIcon mNotifyIconItem"></a>
        </div>
    </div>
    
    <div id="loading" ><img src="http://dspl.innogamescdn.com/8.27.1/22314/graphic/m/ajax-loader.gif?df38d" title="" alt="" class="" /><br />Wczytywanie...</div>
    
    <span id="storage" style="display: none">400000</span>
    
    <div id="mobileHeader">
        <div id="mobileTouch">
                    <div id="mobileMenu" class="mobileMenu">
                <div id="mobileMenuScroll" class="mobileMenuScrollContent">
                    <span class="arrow">&laquo;</span>
                    <a href="/game.php?village=96311&amp;screen=overview">O rety rety atakują ci z Bety !
                    <span class="bonus_icon bonus_icon_8" title="30% większa produkcja surowców (wszystkie surowce)"></span>                <b class="nowrap">(412|412) K76</b></a>
                                                    - <a href="/game.php?village=96311&amp;screen=map">Mapa</a>
                    - <a href="/game.php?village=96311&amp;screen=overview_villages">Przeglądy</a>
                    - <a href="/game.php?village=96311&amp;screen=report">Raporty</a>
                    - <a href="/game.php?village=96311&amp;screen=mail">Wiadomości</a>
                    - <a href="/game.php?village=96311&amp;mode=forum&amp;screen=ally"  style="display:inline"><span id="tribe_forum_indicator" class="icon header new_post" title="Nowy komentarz w forum"></span></a><a href="/game.php?village=96311&amp;screen=ally">Plemię</a>
                    - <a href="/game.php?village=96311&amp;screen=ranking">Ranking</a>
                    - <a href="#" class="needsclick" onclick="$('#mobileMore').toggle(); return false;">Więcej</a>
                                                    <span class="arrow">&raquo;</span>
                </div>
            </div>
                    <div id="mobileMenuSmall">
                            <a href="/game.php?village=96311&amp;screen=wood"><span class="mheader icon wood"></span></a> <span id="wood" title="3120" class="warn" data-amount="400000"></span>
                <a href="/game.php?village=96311&amp;screen=stone"><span class="mheader icon stone"></span></a> <span id="stone" title="3120" class="warn" data-amount="400000"></span>
                <a href="/game.php?village=96311&amp;screen=iron"><span class="mheader icon iron"></span></a> <span id="iron" title="3120" class="warn" data-amount="400000"></span>
                <a href="/game.php?village=96311&amp;screen=farm"><span class="mheader icon pop"></span></a> <span id="pop_current_label">23354</span>/<span id="pop_max_label">24960</span>
                        </div>
        </div>
    
        <div class="mobileDivider"></div>
        <div id="mobileMore">
                    <a href="/game.php?village=96311&amp;screen=info_player" class="profile">Profil</a>
                    <a href="/game.php?village=96311&amp;screen=inventory" class="inventory">Inwentarz</a>
                    <a href="/game.php?village=96311&amp;screen=settings" class="settings">Ustawienia</a>
                    <a href="/game.php?village=96311&amp;screen=premium" class="premium">Premium</a>
                    <a href="/game.php?village=96311&amp;screen=buddies" class="friends">Przyjaciele</a>
                    <a href="/game.php?village=96311&amp;screen=memo" class="notebook">Notatki</a>
                    <a href="/game.php?village=96311&amp;screen=flags" class="flags">Flagi</a>
                    <a href="/game.php?village=96311&amp;mode=inventory&amp;screen=statue" class="knight">Rycerz</a>
                    <a href="/game.php?village=96311&amp;screen=accountmanager" class="am">Menedżer Konta</a>
                    <a href="/game.php?village=96311&amp;screen=am_farm" class="fm">Asystent Farmera</a>
                    <a href="http://help.plemiona.pl" class="help">Pomoc</a>
                    <a href="http://forum.plemiona.pl//index.php" class="extforum">Forum</a>
                    <a href="/game.php?village=96311&amp;action=logout&amp;h=d199&amp;screen=" class="logout">Wylogowanie</a>
                </div>
    </div>
    
    <div id="mobileNav">
        <div><span class="mobileNav" id="mobileNavRight"></span></div>
        <div><span class="mobileNav" id="mobileNavLeft"></span></div>
    </div>
    <div class="mobileNavContent" id="mobileNavContentLeft"></div>
    <div class="mobileNavContent" id="mobileNavContentRight"></div>
    
    <div id="mobileContent">
        <div class="menu" style="display:none; padding:3px;" id="group_popup"></div>
            <div class="error_box" style="display:none;">
    
                </div>
    
    
    
    
    
        <div id="content_value" style="margin: 0 auto">
    
    
    
    <script type="text/javascript">
    $(function(){
        VillageGroups.initOverviews();
    });
    </script>
    <table id="production_table" class="vis small" cellspacing="0">
        <tr style="margin-top:3px;">
        <th style="border-top:1px solid;">
            <span class="quickedit-vn" data-id="96311">
                <span class="quickedit-content">
                    <a href="/game.php?village=96311&amp;screen=overview">
                                                                <span class="quickedit-label" data-text="O rety rety atakują ci z Bety !">
                             O rety rety atakują ci z Bety ! (412|412) K76                     </span>
                        <span class="bonus_icon bonus_icon_8" title="30% większa produkcja surowców (wszystkie surowce)"></span>                </a>
                                    <a class="rename-icon" href="#" title="Zmień nazwę"></a>
                </span>
            </span>
        </th>
    
        <th style="border-top:1px solid;text-align:right;">10<span class="grey">.</span>029</th>
       </tr>
       <tr class="nowrap">
        <td colspan="2" class="nopad">
        <a class="button icon show_more">Dalsze informacje</a>
        <div class="more_info">
          <table width="100%">
           <tr><td>Surowce<br /><table><tr><td><span><span class="warn wood">400<span class="grey">.</span>000</span> <span class="warn stone">400<span class="grey">.</span>000</span> <span class="warn iron">400<span class="grey">.</span>000</span> </span></td></tr></table><hr /></td></tr>
           <tr><td class="nopad">
            <table><tr>
                <td style="border-right:1px dotted;">Spichlerz<br /><table><tr><td><span><img  src="http://dspl.innogamescdn.com/8.27.1/22314/graphic/res.png?0fdfc" alt="" title="Pojemność spichlerza" /> 400000</span></td></tr></table></td>
                <td style="padding-left:5px">Zagroda<br /><table><tr><td><span><span class="icon header population"> </span> 23354/24960</span></td></tr></table></td>
            </tr></table>
            <hr /></td></tr>
            <tr><td><span>Kupcy</span><br /><table><tr><td><a href="/game.php?village=96311&amp;screen=market">110</a></td></tr></table><hr /></td></tr>
                  </table>
        </div>
        </td>
       </tr>
        <tr style="margin-top:3px;">
        <th style="border-top:1px solid;">
            <span class="quickedit-vn" data-id="94464">
                <span class="quickedit-content">
                    <a href="/game.php?village=94464&amp;screen=overview">
                                                                <span class="quickedit-label" data-text="wioska barbarzyńska">
                             wioska barbarzyńska (412|412) K75                     </span>
                                        </a>
                                    <a class="rename-icon" href="#" title="Zmień nazwę"></a>
                </span>
            </span>
        </th>
    
        <th style="border-top:1px solid;text-align:right;">2<span class="grey">.</span>990</th>
       </tr>
       <tr class="nowrap">
        <td colspan="2" class="nopad">
        <a class="button icon show_more">Dalsze informacje</a>
        <div class="more_info">
          <table width="100%">
           <tr><td>Surowce<br /><table><tr><td><span><span class="warn wood">115<span class="grey">.</span>798</span> <span class="warn stone">115<span class="grey">.</span>798</span> <span class="warn iron">115<span class="grey">.</span>798</span> </span></td></tr></table><hr /></td></tr>
           <tr><td class="nopad">
            <table><tr>
                <td style="border-right:1px dotted;">Spichlerz<br /><table><tr><td><span><img  src="http://dspl.innogamescdn.com/8.27.1/22314/graphic/res.png?0fdfc" alt="" title="Pojemność spichlerza" /> 115798</span></td></tr></table></td>
                <td style="padding-left:5px">Zagroda<br /><table><tr><td><span><span class="icon header population"> </span> 1918/2598</span></td></tr></table></td>
            </tr></table>
            <hr /></td></tr>
            <tr><td><span>Kupcy</span><br /><table><tr><td><a href="/game.php?village=94464&amp;screen=market">154</a></td></tr></table><hr /></td></tr>
                  </table>
        </div>
        </td>
       </tr>
    </table>
    
    <script>
        $(function(){
            $('.quickedit-vn').QuickEdit( { url: TribalWars.buildURL('POST', 'main', { ajaxaction: 'change_name', village: '__ID__' } ) } );
        });
    </script>
    </div>
    
        </div>
    
        <div style="clear: both">
                        <p style="float: left; margin-bottom: 0">
                    <a href="/game.php?village=96311&amp;action=set_mobile&amp;h=d199&amp;mobile=0&amp;screen=settings">Wersja przeglądarkowa</a>
                </p>
                    <p style="float: right; margin-bottom: 0">
                <span id="serverTime">21:37:58</span> <span id="serverDate">14/10/2014</span>
            </p>
        </div>
    
        <div id="mNotifySpacer"> </div>
    </div>
    
    
    
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-35100433-1']);
      _gaq.push(['_trackPageview']);
      _gaq.push(['_gat._anonymizeIp']);
    
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
      })();
    
    </script>
    
    
    
    
    <script>
        $(document).ready(function() {
            TribalWars.initTab('9df45365fb');
            Timing.init(1413315478.0743);
    
    
    
    
    
                Connection.connect(8080, 'b3267d405e8f');
    
                UI.Notification.enabled = true;
    
    
            });
    </script>
    
    
    <div id="side-notification-container"></div>
    </body>
    </html>
    

0 个答案:

没有答案