[英]Extract JavaScript String from HTML page with Java
我想获取在html页面中硬编码的特定Javascript变量的值。 按照以下说明访问测试用例:
Shopify.theme
Object {name: "Retina", id: 8528293, theme_store_id: 601, role: "main"}
Shopify.theme.theme_store_id
以上响应来自下面给出的脚本,该脚本存在于所有Shopify商店中。
<script>
//<![CDATA[
var Shopify = Shopify || {};
Shopify.shop = "headphone-zone.myshopify.com";
Shopify.theme = {"name":"Retina","id":8528293,"theme_store_id":601,"role":"main"};
//]]>
</script>
如何编写Java代码以获取Shopify.theme.theme_store_id
字段的值并将其存储?
。
String patternString = "Shopify.theme\\s*=\\s*.*theme_store_id\\"\\:(\\d+)";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(text);
String themeStoreId;
while (matcher.find()) {
themeStoreId = matcher.group(1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.