【问题标题】:UrlFetchApp.fetch windows-1251UrlFetchApp.fetch windows-1251
【发布时间】:2013-01-10 01:34:58
【问题描述】:

我想得到主机的标题页

我希望得到 Страховые компании Уфы。 Адреса отделений в Уфе

然后得到 ��������������������. ���������������� �����

示例脚本:

function doGet() {
  var options1 = {
    contentType: "text/html; charset=windows-1251",
    muteHttpExceptions: true
  };
  var url_catalog = 'http://ufa.insure-company.ru/';
  var response = UrlFetchApp.fetch(url_catalog, options1);
  var txt = response.getContentText();
  doc = Xml.parse(txt, true);
  var tbody = doc.html.head;
  var title = tbody.getElements("title");
  var t = title[0].getText();
  return HtmlService.createHtmlOutput(t);
}

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:
    function doGet() {
      var options1 = {
        contentType: "text/html ",
        muteHttpExceptions: true
     };
      var url_catalog = 'http://ufa.insure-company.ru/';
      var response = UrlFetchApp.fetch(url_catalog, options1).getContentText("windows-1251");      
      doc = Xml.parse(response, true);
      var tbody = doc.html.head;
      var title = tbody.getElements("title");
      var t = title[0].getText();
      return HtmlService.createHtmlOutput(t);
    }
    

    原来是在老产品论坛里回答的,看答案here

    您可以使用 getContentText() 在 UrlFetchApp 类中获取上下文。

    Working example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-26
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 2016-06-11
      相关资源
      最近更新 更多