【发布时间】:2017-06-25 18:15:08
【问题描述】:
在 HTML 页面中,我想选择一个 javascript 变量的值。下面是 HTML 页面的 sn-p。
<script id="page-data">
var __IS_MIRA__;
var __INITIAL_STATE__ = undefined;
var __CACHE_REGISTRY__ = undefined;
var __NEXT_CACHE_ID__ = undefined;
var __DMP_CONFIG__ = {"context":{"access_token":null,"ad_sync_script_url":"http:\/\/www.taolao.com\/cdn\/manifest\/video\/x7775n8.m3u8?auth=1498553714-2562-k2kou1s3-7be1a0645b68824508f7f4989900d487yk2kou1s3&bs=1","admin":false,"as_number":"AS18403","user":null}
我的目标是使用 jsoup 从此页面读取变量 DMP_CONFIG 的值。 jsoup可以吗?如果是,那怎么办?
这是我的 Java 代码。
Document doc = Jsoup.connect(""+urlhtml).get();
Element div = doc.getElementById("page-data");
Pattern p = Pattern.compile("(?is) __DMP_CONFIG__ = \"(.+?)\""); // Regex for the value of the key
Matcher m = p.matcher(div.html());
while( m.find() ) {
mData =m.group(1);
}
【问题讨论】:
标签: javascript java android jsoup