UrlFetchApp没有返回完整的源代码。

huangapple go评论74阅读模式
英文:

UrlFetchApp is not return full source code

问题

以下是要翻译的代码部分:

If I try to simply get the source html of a page I cannot get the full source. It breaks in some point. Returns less than half of the exact source html.

var pagedata = UrlFetchApp.fetch("https://stackoverflow.com");

var html = pagedata.getContentText();

Logger.log(html);

returns:

[20-01-06 11:37:12:483 AST] <!DOCTYPE html>


    <html class="html__responsive html__unpinned-leftnav">

    <head>

        <title>Stack Overflow - Where Developers Learn, Share, &amp; Build Careers</title>
        <link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d">
        <link rel="apple-touch-icon" href="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a">
        <link rel="image_src" href="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a"> 
        <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
        <meta name="description" content="Stack Overflow is the largest, most trusted online community for developers to learn, share​ ​their programming ​knowledge, and build their careers."/>
        <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">


        <meta property="og:type" content= "website" />
        <meta property="og:url" content="https://stackoverflow.com/"/>
        <meta property="og:site_name" content="Stack Overflow" />
        <meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded" />
        <meta name="twitter:card" content="summary"/>
        <meta name="twitter:domain" content="stackoverflow.com"/>
        <meta name="twitter:title" property="og:title" itemprop="name" content="Stack Overflow - Where Developers Learn, Share, &amp; Build Careers" />
        <meta name="twitter:description" property="og:description" itemprop="description" content="Stack Overflow | The World’s Largest Online Community for Developers" />
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://cdn.sstatic.net/Js/stub.en.js?v=805608b6266c"></script>
    
    <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/stacks.css?v=d0797a2dd6f2" >
    <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/stackoverflow/primary.css?v=b556f32ececa" >

    
    <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/Product/product.css?v=b21a396b1289" >

    <link rel="alternate" type="application/atom+xml" title="Feed of recent questions" href="/feeds">


        
        
        <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/Channels/channels.css?v=05e29db3ebd2" >
        
        
        

        <script>
        StackExchange.init({"locale":"en","serverTime":1578299832,"routeName":"Home/Index","stackAuthUrl":"https://stackauth.com","networkMetaHostname":"meta.stackexchange.com","site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers","isNoticesTabEnabled":true,"enableNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"id":1,"childUrl":"https://meta.stackoverflow.com","negativeVoteScoreFloor":null,"enableSocialMediaInSharePopup":true,"protocol":"https"},"user":{"fkey":"57ec692c216f7cb3d5bad86dceda031ede043f08f80e49d7b3a503d818751da0","tid":"0e7426d0-71e0-4546-1387-57279d43b924","rep":0,"isAnonymous":true,"isAnonymousNetworkWide":true},"events":{"postType":{"question":1},"postEditionSection":{"title":1,"body":2,"tags":3}},"story":{"minCompleteBodyLength":75,"likedTagsMaxLength":300,"dislikedTagsMaxLength":300},"jobPreferences":{"maxNumDeveloperRoles":2,"maxNumIndustries":4},"svgIconPath":"https://cdn.sstatic.net/Img/svg-icons","svgIconHash":"53ac0f6119d0"}, {"userProfile":{"openGraphAPIKey":"4a307e43-b625-49bb-af15-ffadf2bda017"},"userMessaging":{},"tags":{},"snippets":{"renderDomain":"stacksnippets.net","snippetsEnabled":true},"slack":{"sidebarAdDismissCookie":"slack-sidebar-ad"},"site":{"allowImageUploads":true,"enableImgurHttps":true,"enableUserHovercards":true,"forceHttpsImages":true,"styleCode":true},"questions":{"showPostNoticesV2":true},"paths":{},"monitoring":{"clientTimingsAbsoluteTimeout":30000,"clientTimingsDebounceTimeout":1000},"mentions":{"maxNumUsersInDropdown":50},"markdown":{"asteriskIntraWordEmphasis":true},"flags":{"allowRetractingCommentFlags":true,"allowRetractingFlags":true},"comments":{},"accounts":{"currentPasswordRequiredForChangingStackIdPassword":true}});
        StackExchange.using.setCacheBreakers({"js/prettify-full.en.js":"e75c65979e48","js/moderator.en.js":"b6ce25c91468","js/full-anon.en.js":"bcefec08f832","js/full.en.js":"bf88016bdeb3","js/wmd.en.js":"28e8cee04c52","js/mobile.en.js":"a168d277c579","js/help.en.js":"373025d0518f","js/tageditor.en.js":"693662f7ff37","js/tageditornew.en.js":"803d1cb2516d","js/inline-tag-editing.en.js":"b5436857e5dd","js/revisions.en.js":"055fbe1202e9","js/review.en.js":"7b6845367497","js/tagsuggestions.en.js":"dba299567acf","js/post-validation.en.js":"bc3e5be5330d","js/explore-qlist.en.js":"8498d0bb288b","js/events.en.js":"57fa0feb2feb","js/keyboard-shortcuts.en.js":"ab1fdc223933","js/adops.en.js":"6b9883f0531e","js/begin-edit-event.en.js":"cb9965ad8784","js/ask.en.js":"

<details>
<summary>英文:</summary>

If I try to simply get the source html of a page I cannot get the full source. It breaks in some point. Returns less than half of the exact source html.

      var pagedata = UrlFetchApp.fetch(&quot;https://stackoverflow.com&quot;);
      
      var html = pagedata.getContentText();

      Logger.log(html);

returns:

    [20-01-06 11:37:12:483 AST] &lt;!DOCTYPE html&gt;
    
    
        &lt;html class=&quot;html__responsive html__unpinned-leftnav&quot;&gt;
    
        &lt;head&gt;
    
            &lt;title&gt;Stack Overflow - Where Developers Learn, Share, &amp;amp; Build Careers&lt;/title&gt;
            &lt;link rel=&quot;shortcut icon&quot; href=&quot;https://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d&quot;&gt;
            &lt;link rel=&quot;apple-touch-icon&quot; href=&quot;https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a&quot;&gt;
            &lt;link rel=&quot;image_src&quot; href=&quot;https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a&quot;&gt; 
            &lt;link rel=&quot;search&quot; type=&quot;application/opensearchdescription+xml&quot; title=&quot;Stack Overflow&quot; href=&quot;/opensearch.xml&quot;&gt;
            &lt;meta name=&quot;description&quot; content=&quot;Stack Overflow is the largest, most trusted online community for developers to learn, share their programming knowledge, and build their careers.&quot;/&gt;
            &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0&quot;&gt;
    
    
            &lt;meta property=&quot;og:type&quot; content= &quot;website&quot; /&gt;
            &lt;meta property=&quot;og:url&quot; content=&quot;https://stackoverflow.com/&quot;/&gt;
            &lt;meta property=&quot;og:site_name&quot; content=&quot;Stack Overflow&quot; /&gt;
            &lt;meta property=&quot;og:image&quot; itemprop=&quot;image primaryImageOfPage&quot; content=&quot;https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded&quot; /&gt;
            &lt;meta name=&quot;twitter:card&quot; content=&quot;summary&quot;/&gt;
            &lt;meta name=&quot;twitter:domain&quot; content=&quot;stackoverflow.com&quot;/&gt;
            &lt;meta name=&quot;twitter:title&quot; property=&quot;og:title&quot; itemprop=&quot;name&quot; content=&quot;Stack Overflow - Where Developers Learn, Share, &amp;amp; Build Careers&quot; /&gt;
            &lt;meta name=&quot;twitter:description&quot; property=&quot;og:description&quot; itemprop=&quot;description&quot; content=&quot;Stack Overflow | The Worlds Largest Online Community for Developers&quot; /&gt;
                &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js&quot;&gt;&lt;/script&gt;
            &lt;script src=&quot;https://cdn.sstatic.net/Js/stub.en.js?v=805608b6266c&quot;&gt;&lt;/script&gt;
        
        &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.sstatic.net/Shared/stacks.css?v=d0797a2dd6f2&quot; &gt;
        &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.sstatic.net/Sites/stackoverflow/primary.css?v=b556f32ececa&quot; &gt;
    
        
        &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.sstatic.net/Shared/Product/product.css?v=b21a396b1289&quot; &gt;
    
        &lt;link rel=&quot;alternate&quot; type=&quot;application/atom+xml&quot; title=&quot;Feed of recent questions&quot; href=&quot;/feeds&quot;&gt;
    
    
            
            
            
            &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.sstatic.net/Shared/Channels/channels.css?v=05e29db3ebd2&quot; &gt;
            
            
            
    
    
            &lt;script&gt;
            StackExchange.init({&quot;locale&quot;:&quot;en&quot;,&quot;serverTime&quot;:1578299832,&quot;routeName&quot;:&quot;Home/Index&quot;,&quot;stackAuthUrl&quot;:&quot;https://stackauth.com&quot;,&quot;networkMetaHostname&quot;:&quot;meta.stackexchange.com&quot;,&quot;site&quot;:{&quot;name&quot;:&quot;Stack Overflow&quot;,&quot;description&quot;:&quot;Q&amp;A for professional and enthusiast programmers&quot;,&quot;isNoticesTabEnabled&quot;:true,&quot;enableNewTagCreationWarning&quot;:true,&quot;insertSpaceAfterNameTabCompletion&quot;:false,&quot;id&quot;:1,&quot;childUrl&quot;:&quot;https://meta.stackoverflow.com&quot;,&quot;negativeVoteScoreFloor&quot;:null,&quot;enableSocialMediaInSharePopup&quot;:true,&quot;protocol&quot;:&quot;https&quot;},&quot;user&quot;:{&quot;fkey&quot;:&quot;57ec692c216f7cb3d5bad86dceda031ede043f08f80e49d7b3a503d818751da0&quot;,&quot;tid&quot;:&quot;0e7426d0-71e0-4546-1387-57279d43b924&quot;,&quot;rep&quot;:0,&quot;isAnonymous&quot;:true,&quot;isAnonymousNetworkWide&quot;:true},&quot;events&quot;:{&quot;postType&quot;:{&quot;question&quot;:1},&quot;postEditionSection&quot;:{&quot;title&quot;:1,&quot;body&quot;:2,&quot;tags&quot;:3}},&quot;story&quot;:{&quot;minCompleteBodyLength&quot;:75,&quot;likedTagsMaxLength&quot;:300,&quot;dislikedTagsMaxLength&quot;:300},&quot;jobPreferences&quot;:{&quot;maxNumDeveloperRoles&quot;:2,&quot;maxNumIndustries&quot;:4},&quot;svgIconPath&quot;:&quot;https://cdn.sstatic.net/Img/svg-icons&quot;,&quot;svgIconHash&quot;:&quot;53ac0f6119d0&quot;}, {&quot;userProfile&quot;:{&quot;openGraphAPIKey&quot;:&quot;4a307e43-b625-49bb-af15-ffadf2bda017&quot;},&quot;userMessaging&quot;:{},&quot;tags&quot;:{},&quot;snippets&quot;:{&quot;renderDomain&quot;:&quot;stacksnippets.net&quot;,&quot;snippetsEnabled&quot;:true},&quot;slack&quot;:{&quot;sidebarAdDismissCookie&quot;:&quot;slack-sidebar-ad&quot;},&quot;site&quot;:{&quot;allowImageUploads&quot;:true,&quot;enableImgurHttps&quot;:true,&quot;enableUserHovercards&quot;:true,&quot;forceHttpsImages&quot;:true,&quot;styleCode&quot;:true},&quot;questions&quot;:{&quot;showPostNoticesV2&quot;:true},&quot;paths&quot;:{},&quot;monitoring&quot;:{&quot;clientTimingsAbsoluteTimeout&quot;:30000,&quot;clientTimingsDebounceTimeout&quot;:1000},&quot;mentions&quot;:{&quot;maxNumUsersInDropdown&quot;:50},&quot;markdown&quot;:{&quot;asteriskIntraWordEmphasis&quot;:true},&quot;flags&quot;:{&quot;allowRetractingCommentFlags&quot;:true,&quot;allowRetractingFlags&quot;:true},&quot;comments&quot;:{},&quot;accounts&quot;:{&quot;currentPasswordRequiredForChangingStackIdPassword&quot;:true}});
            StackExchange.using.setCacheBreakers({&quot;js/prettify-full.en.js&quot;:&quot;e75c65979e48&quot;,&quot;js/moderator.en.js&quot;:&quot;b6ce25c91468&quot;,&quot;js/full-anon.en.js&quot;:&quot;bcefec08f832&quot;,&quot;js/full.en.js&quot;:&quot;bf88016bdeb3&quot;,&quot;js/wmd.en.js&quot;:&quot;28e8cee04c52&quot;,&quot;js/mobile.en.js&quot;:&quot;a168d277c579&quot;,&quot;js/help.en.js&quot;:&quot;373025d0518f&quot;,&quot;js/tageditor.en.js&quot;:&quot;693662f7ff37&quot;,&quot;js/tageditornew.en.js&quot;:&quot;803d1cb2516d&quot;,&quot;js/inline-tag-editing.en.js&quot;:&quot;b5436857e5dd&quot;,&quot;js/revisions.en.js&quot;:&quot;055fbe1202e9&quot;,&quot;js/review.en.js&quot;:&quot;7b6845367497&quot;,&quot;js/tagsuggestions.en.js&quot;:&quot;dba299567acf&quot;,&quot;js/post-validation.en.js&quot;:&quot;bc3e5be5330d&quot;,&quot;js/explore-qlist.en.js&quot;:&quot;8498d0bb288b&quot;,&quot;js/events.en.js&quot;:&quot;57fa0feb2feb&quot;,&quot;js/keyboard-shortcuts.en.js&quot;:&quot;ab1fdc223933&quot;,&quot;js/adops.en.js&quot;:&quot;6b9883f0531e&quot;,&quot;js/begin-edit-event.en.js&quot;:&quot;cb9965ad8784&quot;,&quot;js/ask.en.js&quot;:&quot;e4dd8c66240e&quot;,&quot;js/question-editor.en.js&quot;:&quot;&quot;,&quot;js/snippet-javascript-codemirror.en.js&quot;:&quot;07eb23cd1f61&quot;});
            StackExchange.using(&quot;gps&quot;, function() {
                 StackExchange.gps.init(true);
            });
        &lt;/script&gt;
        &lt;noscript id=&quot;noscript-css&quot;&gt;&lt;style&gt;body,.top-bar{margin-top:1.9em}&lt;/style&gt;&lt;/noscript&gt;
        &lt;/head&gt;
            &lt;body class=&quot;home-page unified-theme&quot;&gt;
        &lt;div id=&quot;notify-container&quot;&gt;&lt;/div&gt;
        &lt;div id=&quot;custom-header&quot;&gt;&lt;/div&gt;
    
    
    
    
    &lt;header class=&quot;top-bar js-top-bar top-bar__network _fixed&quot;&gt;
        &lt;div class=&quot;wmx12 mx-auto grid ai-center h100&quot; role=&quot;menubar&quot;&gt;
            &lt;div class=&quot;-main grid--cell&quot;&gt;
                    &lt;a href=&quot;#&quot; class=&quot;left-sidebar-toggle p0 ai-center jc-center js-left-sidebar-toggle&quot; role=&quot;menuitem&quot; aria-haspopup=&quot;true&quot; aria-controls=&quot;left-sidebar&quot; aria-expanded=&quot;false&quot;&gt;&lt;span class=&quot;ps-relative&quot;&gt;&lt;/span&gt;&lt;/a&gt;
                    &lt;div class=&quot;topbar-dialog leftnav-dialog js-leftnav-dialog dno&quot;&gt;
                        &lt;div class=&quot;left-sidebar js-unpinned-left-sidebar&quot; data-can-be=&quot;left-sidebar&quot; data-is-here-when=&quot;sm md lg&quot;&gt;&lt;/div&gt;
                    &lt;/div&gt;
                                    &lt;a href=&quot;https://stackoverflow.com&quot; class=&quot;-logo js-gps-track&quot;
                            data-gps-track=&quot;top_nav.click({is_current:true, location:1, destination:8})&quot;&gt;
                            &lt;span class=&quot;-img _glyph&quot;&gt;Stack Overflow&lt;/span&gt;
                        &lt;/a&gt;
    
    
    
            &lt;/div&gt;
    
                &lt;ol class=&quot;list-reset grid gs4&quot; role=&quot;presentation&quot;&gt;
                    &lt;li class=&quot;grid--cell&quot;&gt;
                        &lt;a href=&quot;#&quot;
                            class=&quot;-marketing-link is-selected js-gps-track js-products-menu&quot;
                            aria-controls=&quot;products-popover&quot;
                            data-controller=&quot;s-popover&quot;
                            data-action=&quot;s-popover#toggle&quot;
                            data-s-popover-placement=&quot;bottom&quot;
                            data-gps-track=&quot;top_nav.products.click({location:1, destination:1})&quot;
                            data-ga=&quot;[&amp;quot;top navigation&amp;quot;,&amp;quot;products menu click&amp;quot;,null,null,null]&quot;&gt;
                            Products
                        &lt;/a&gt;
                    &lt;/li&gt;
    
                        &lt;li class=&quot;grid--cell md:d-none&quot;&gt;
                            &lt;a href=&quot;/teams/customers&quot; class=&quot;-marketing-link js-gps-track&quot;
                               data-gps-track=&quot;top_nav.products.click({location:1, destination:7})&quot;
                                data-ga=&quot;[&amp;quot;top navigation&amp;quot;,&amp;quot;customers menu click&amp;quot;,null,null,null]&quot;&gt;Customers&lt;/a&gt;
                        &lt;/li&gt;
                        &lt;li class=&quot;grid--cell md:d-none&quot;&gt;
                            &lt;a href=&quot;/teams/use-cases&quot; class=&quot;-marketing-link js-gps-track&quot;
                               data-gps-track=&quot;top_nav.products.click({location:1, destination:8})&quot;
                               data-ga=&quot;[&amp;quot;top navigation&amp;quot;,&amp;quot;use cases menu click&amp;quot;,null,null,null]&quot;&gt;Use cases&lt;/a&gt;
                        &lt;/li&gt;
              
Original source has 4168 lines. First of all there is no closing body, html tags. How can I get the full source code of a page with UrlFetchApp?

</details>


# 答案1
**得分**: 1

The Logger.log() method expects a string or other JavaScript object. The logs can only hold a limited amount of data, so avoid logging large amounts of text.

[Source][1]

The character limit for the logger.log function is not specified, but your variable *html* does contain all of your data.

[1]: https://developers.google.com/apps-script/guides/logging

<details>
<summary>英文:</summary>

The Logger.log() method expects a string or other JavaScript object. The logs can only hold a limited amount of data, so avoid logging large amounts of text.

[Source][1]

The character limit for the logger.log function is not specified, but your variable *html* does contain all of your data.




  [1]: https://developers.google.com/apps-script/guides/logging

</details>



huangapple
  • 本文由 发表于 2020年1月6日 16:54:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609135.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定