嘿我试图从节点中的HTML请求结果中访问全局变量。我目前可以使用cheerio模块访问节点,但是我对如何访问全局页面变量感到难过?
private static final String PARSE_PATTERN = "yyyy-MM-dd'T'HH:mm:ssXXX";
private static final String FORMAT_PATTERN = "MM/dd/yyyy";
// we cannot declare the SimpleDateFormat as static since it isn't thread-safe
public static String formatResolutionTime(String startDateString) {
try {
DateFormat parser = new SimpleDateFormat(PARSE_PATTERN);
Date startDate = parser.parse(startDateString);
DateFormat formatter = new SimpleDateFormat(FORMAT_PATTERN);
return formatter.format(startDate);
} catch (ParseException e) {
// e.printStackTrace();
return "Error"; // or whatever, but return a string here
}
}

答案 0 :(得分:1)
Cheerio无权访问浏览器的java脚本全局变量。它只能解析html页面的DOM结构。
请参阅其他答案作为来源:
How can I use Node / Cheerio (or something else) to scrape a global variable from a site?