鍍金池/ 問答/數據分析&挖掘  Java  HTML/ java 爬蟲如何獲取with( document) with (body) 中

java 爬蟲如何獲取with( document) with (body) 中的body 內容?

用http請求一個鏈接獲取如下內容

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="data-spm" content="a21ag"/>
  <meta name="renderer" content="webkit">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>生意參謀</title>

    
  
  
      <link rel="stylesheet" href=//g.alicdn.com/dt/op-ebase/3.4.41/op-ebase.css />
    <link rel="stylesheet" href=//g.alicdn.com/dt/op-eportal/1.12.20/login.css />
    <!--[if lte IE 9]>
  <script>if (!/update\.htm/.test(location.href)) window.location = '//sycm.taobao.com/portal/update.htm'; </script>
  <![endif]-->
</head>
<body class="esycm-wrapper" data-spm="8365346"><script>
with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","category=&userid=&aplus&yunid=&&asid=AQAAAADhb8xakfQWKgAAAABSM9G79i330w==",id="tb-beacon-aplus",src=(location>"https"?"http://g":"http://g")+".alicdn.com/alilog/mlog/aplus_v2.js")
</script>
  <div id="app"></div>
      <script type="text/javascript" src=//g.alicdn.com/dt/op-ebase/3.4.41/op-ebase.js crossorigin></script>
    <script type="text/javascript" src=//g.alicdn.com/dt/op-eportal/1.12.20/login.js crossorigin></script>
  </body>
</html>

body沒有顯示出來如獲取呢?

回答
編輯回答
乞許

你這種情況需要用到無頭瀏覽器才行的。相當于要等js執(zhí)行后,你再解析內容。
如果是node來寫的話,可能比較方便,使用PhantomJS實現起來比較方便。

不過,java環(huán)境下的HtmlUnit兼容性稍弱,你可以試試看

2018年3月27日 05:35