【问题标题】:Scraping website with node.js request and getting weird characters使用 node.js 请求抓取网站并获取奇怪的字符
【发布时间】:2016-12-09 16:28:01
【问题描述】:

我使用了 nwjs(版本 0.18.8),并在 mangafox.me 上请求做一个 mangareader。

它适用于http://mangafox.me/directory/

当我尝试对像 http://mangafox.me/manga/onepunch_man/vTBD/c066/1.html 这样的漫画图像提出请求时,我得到了这些奇怪的符号:

��{s�F��[��w#Y�\�AI�(tY��dϯ����M%9���@�Cw��~����I(v�� 带入... 0�3? y`Y�_̘gY|fY���\�Q2�������M���nV�iz�g���b$W�_a���c�C5

我该如何解决这个问题?

【问题讨论】:

    标签: javascript node.js web-scraping nwjs


    【解决方案1】:

    没关系 x) 实际上只是输出被压缩成 zip,所以如果你想解决它,如果你有同样的问题,只需在请求标头中添加 gzip: true Ex:

    request({url: '*****', gzip: true}, function(err, res, html){
    
       if (!error && response.statusCode == 200) {
    
       //Do something
    
       }
    
    });
    

    【讨论】:

      【解决方案2】:

      你不需要 node.js 来做这么简单的事情。抓取网站的最简单方法是将其加载到隐藏的 iframe 中,然后循环遍历文档中所需的元素数组。

      加载的文档为您提供了像这样的数组中的所有内容...

       Frame.contentWindow.document.forms
      
       Frame.contentWindow.document.scripts
      
       Frame.contentWindow.document.styleSheets
      
       Frame.contentWindow.document.embeds
      
       Frame.contentWindow.document.cookie
      
       Frame.contentWindow.document.images
      
       Frame.contentWindow.document.links
      

      等等……

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多