Attachment 'fetch-url.js'

Download

   1 const fetch = require('node-fetch');
   2 
   3 async function getTitle(url) {
   4   let response = await fetch(url)
   5   let html = await response.text()
   6   return html.match(/<title>([\s\S]+)<\/title>/i)[1]
   7 }
   8 
   9 let url = 'https://tc39.github.io/ecma262/'
  10 
  11 getTitle(url).then(console.log)
  12 
  13 // async 函数的写法
  14 const loadContent = async (url) => {
  15   const res = await fetch(url)
  16   return res.text()
  17 };
  18 
  19 loadContent(url).then(content => console.log(content.match(/<title>([\s\S]+)<\/title>/i)[1]));

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2018-06-27 19:04:47, 0.5 KB) [[attachment:fetch-url.js]]
  • [get | view] (2018-06-27 19:04:47, 0.5 KB) [[attachment:fetch-urls-concurrently.js]]
  • [get | view] (2018-06-26 18:17:56, 0.3 KB) [[attachment:gen-synch.js]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.