久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='j6Via'></small><noframes id='j6Via'>

  • <tfoot id='j6Via'></tfoot>

      <bdo id='j6Via'></bdo><ul id='j6Via'></ul>
  • <legend id='j6Via'><style id='j6Via'><dir id='j6Via'><q id='j6Via'></q></dir></style></legend>
    1. <i id='j6Via'><tr id='j6Via'><dt id='j6Via'><q id='j6Via'><span id='j6Via'><b id='j6Via'><form id='j6Via'><ins id='j6Via'></ins><ul id='j6Via'></ul><sub id='j6Via'></sub></form><legend id='j6Via'></legend><bdo id='j6Via'><pre id='j6Via'><center id='j6Via'></center></pre></bdo></b><th id='j6Via'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='j6Via'><tfoot id='j6Via'></tfoot><dl id='j6Via'><fieldset id='j6Via'></fieldset></dl></div>

        如何使用 XMLHttpRequest 在后臺下載 HTML 頁面并從中

        How to use XMLHttpRequest to download an HTML page in the background and extract a text element from it?(如何使用 XMLHttpRequest 在后臺下載 HTML 頁面并從中提取文本元素?)
        1. <legend id='W4lFL'><style id='W4lFL'><dir id='W4lFL'><q id='W4lFL'></q></dir></style></legend>
          <i id='W4lFL'><tr id='W4lFL'><dt id='W4lFL'><q id='W4lFL'><span id='W4lFL'><b id='W4lFL'><form id='W4lFL'><ins id='W4lFL'></ins><ul id='W4lFL'></ul><sub id='W4lFL'></sub></form><legend id='W4lFL'></legend><bdo id='W4lFL'><pre id='W4lFL'><center id='W4lFL'></center></pre></bdo></b><th id='W4lFL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='W4lFL'><tfoot id='W4lFL'></tfoot><dl id='W4lFL'><fieldset id='W4lFL'></fieldset></dl></div>

            <bdo id='W4lFL'></bdo><ul id='W4lFL'></ul>
              <tfoot id='W4lFL'></tfoot>

                  <tbody id='W4lFL'></tbody>

                • <small id='W4lFL'></small><noframes id='W4lFL'>

                  本文介紹了如何使用 XMLHttpRequest 在后臺下載 HTML 頁面并從中提取文本元素?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想制作一個 Greasemonkey 腳本,當您在 URL_1 中時,該腳本會在后臺解析 URL_2 的整個 HTML 網頁,以便從中提取文本元素.

                  I want to make a Greasemonkey script that, while you are in URL_1, the script parses the whole HTML web page of URL_2 in the background in order to extract a text element from it.

                  具體來說,我想在后臺下載整個頁面的HTML代碼(一個爛番茄頁面)并將其存儲在一個變量中,然后使用getElementsByClassName[0] 以便從類名為critic_consensus"的元素中提取我想要的文本.

                  To be specific, I want to download the whole page's HTML code (a Rotten Tomatoes page) in the background and store it in a variable and then use getElementsByClassName[0] in order to extract the text I want from the element with class name "critic_consensus".


                  我在 MDN 中找到了這個:XMLHttpRequest 中的 HTML所以,我最終得到了這個不幸的非工作代碼:


                  I've found this in MDN: HTML in XMLHttpRequest so, I ended up in this unfortunately non-working code:

                  var xhr = new XMLHttpRequest();
                  xhr.onload = function() {
                    alert(this.responseXML.getElementsByClassName(critic_consensus)[0].innerHTML);
                  }
                  xhr.open("GET", "http://www.rottentomatoes.com/m/godfather/",true);
                  xhr.responseType = "document";
                  xhr.send();
                  

                  當我在 Firefox Scratchpad 中運行它時,它會顯示此錯誤消息:

                  It shows this error message when I run it in Firefox Scratchpad:

                  跨域請求被阻止:同源策略不允許讀取http://www.rottentomatoes.com/m/godfather/ 的遠程資源.這可以通過將資源移動到同一域或啟用 CORS.

                  Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.rottentomatoes.com/m/godfather/. This can be fixed by moving the resource to the same domain or enabling CORS.


                  PS.我不使用爛番茄 API 的原因是 他們已經刪除了批評者的共識.

                  推薦答案

                  對于跨域請求,獲取的站點沒有幫助設置許可CORS 策略,Greasemonkey 提供 GM_xmlhttpRequest() 函數.(大多數其他用戶腳本引擎也提供此功能.)

                  For cross-origin requests, where the fetched site has not helpfully set a permissive CORS policy, Greasemonkey provides the GM_xmlhttpRequest() function. (Most other userscript engines also provide this function.)

                  GM_xmlhttpRequest 明確設計為允許跨域請求.

                  GM_xmlhttpRequest is expressly designed to allow cross-origin requests.

                  要獲取您的目標信息,請在結果上創建一個 DOMParser.不要使用 jQuery 方法,因為這會導致加載無關的圖像、腳本和對象、減慢速度或使頁面崩潰.

                  To get your target information create a DOMParser on the result. Do not use jQuery methods as this will cause extraneous images, scripts and objects to load, slowing things down, or crashing the page.

                  這里有一個完整的腳本來說明這個過程:

                  Here's a complete script that illustrates the process:

                  // ==UserScript==
                  // @name        _Parse Ajax Response for specific nodes
                  // @include     http://stackoverflow.com/questions/*
                  // @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
                  // @grant       GM_xmlhttpRequest
                  // ==/UserScript==
                  
                  GM_xmlhttpRequest ( {
                      method: "GET",
                      url:    "http://www.rottentomatoes.com/m/godfather/",
                      onload: function (response) {
                          var parser  = new DOMParser ();
                          /* IMPORTANT!
                              1) For Chrome, see
                              https://developer.mozilla.org/en-US/docs/Web/API/DOMParser#DOMParser_HTML_extension_for_other_browsers
                              for a work-around.
                  
                              2) jQuery.parseHTML() and similar are bad because it causes images, etc., to be loaded.
                          */
                          var doc         = parser.parseFromString (response.responseText, "text/html");
                          var criticTxt   = doc.getElementsByClassName ("critic_consensus")[0].textContent;
                  
                          $("body").prepend ('<h1>' + criticTxt + '</h1>');
                      },
                      onerror: function (e) {
                          console.error ('**** error ', e);
                      },
                      onabort: function (e) {
                          console.error ('**** abort ', e);
                      },
                      ontimeout: function (e) {
                          console.error ('**** timeout ', e);
                      }
                  } );
                  

                  這篇關于如何使用 XMLHttpRequest 在后臺下載 HTML 頁面并從中提取文本元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                • <tfoot id='sFPV3'></tfoot>

                • <legend id='sFPV3'><style id='sFPV3'><dir id='sFPV3'><q id='sFPV3'></q></dir></style></legend>

                        <bdo id='sFPV3'></bdo><ul id='sFPV3'></ul>
                          <tbody id='sFPV3'></tbody>

                            <small id='sFPV3'></small><noframes id='sFPV3'>

                            <i id='sFPV3'><tr id='sFPV3'><dt id='sFPV3'><q id='sFPV3'><span id='sFPV3'><b id='sFPV3'><form id='sFPV3'><ins id='sFPV3'></ins><ul id='sFPV3'></ul><sub id='sFPV3'></sub></form><legend id='sFPV3'></legend><bdo id='sFPV3'><pre id='sFPV3'><center id='sFPV3'></center></pre></bdo></b><th id='sFPV3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sFPV3'><tfoot id='sFPV3'></tfoot><dl id='sFPV3'><fieldset id='sFPV3'></fieldset></dl></div>
                            主站蜘蛛池模板: 久久精品aaa | av免费在线观看网站 | 日韩精品一区二 | 大伊人久久 | 国产精久久久久久 | 超碰人人人人 | 午夜影院污 | a看片| 欧美成人h版在线观看 | 久久精品国产久精国产 | 9191在线观看 | 日韩一区二区三区在线观看 | 99日韩| 亚洲成人动漫在线观看 | 欧美性受 | 日本久久综合 | 一级大片网站 | 国产91综合一区在线观看 | pacopacomama在线 | 欧美网址在线观看 | 国产精品视频久久 | 九色网址| 2019天天操| 天天干人人 | 国产污视频在线 | 欧美日韩亚洲成人 | www.日韩| 天天操,夜夜爽 | www.色婷婷 | 国产精品久久久乱弄 | 日韩成人在线观看 | 成人福利网 | 欧美一区二 | av资源在线看 | 91久久国产综合久久91精品网站 | 日韩成人| 久久久入口 | 日本免费一区二区三区四区 | 欧美国产日韩一区二区三区 | 午夜二区 | 成人精品福利 |