问一下怎么看天猫源码的促销价

J2EE 码拜 8年前 (2016-03-16) 1022次浏览
打开天猫详情页:
http://detail.tmall.com/item.htm?spm=a220m.1000858.1000725.6.6WYs3h&id=27478848618&areaId=320500&cat_id=50025784&rn=36535b7f9c8501df579a59e7fedf719a&user_id=675822543&is_b=1
查看源码发现,促销价并没有显示,这个肯定是ajax异步加载出来的,但是死活半天没找出是哪个js里的代码加载出来的,谁能帮看下,给个满分送你,谢谢。
解决方案

20

参考下列代码:
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
JavaScriptEngine engine = new JavaScriptEngine(client);
client.setJavaScriptEngine(engine);
WebClientOptions opts = client.getOptions();
opts.setThrowExceptionOnScriptError(false);
HtmlPage page = client.getPage(URL_HZW);
toLoadJS(page);
ScriptResult result = page.executeJavaScript(“toFetchEpisodes()”);
Object javaScriptResult = result.getJavaScriptResult();
System.out.println(javaScriptResult);
protected static void toLoadJS(HtmlPage page) throws IOException{
URL url = TEST.class.getResource(“/”);
String filename = url.toString() + “Core.js”;
filename = filename.replace(“file:/”, “”);
File file = new File(filename);
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] bytes = new byte[bis.available()];
bis.read(bytes);
bis.close();
String js = new String(bytes);
page.executeJavaScript(js);
}
Core.js
function toFetchEpisodes(){
var children = $(“.play-list”).children();
var contents = [];
$(children).each(function(item){
contents.push($(item).html());
});
return contents.join(“,”);
}

5

http://g.tbcdn.cn/tm/detail/1.6.34/??model/productCombo.js?t=1_2013072520131122.js

15

引用:
Quote: 引用:

参考下列代码:
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
JavaScriptEngine engine = new JavaScriptEngine(client);
client.setJavaScriptEngine(engine);
WebClientOptions opts = client.getOptions();
opts.setThrowExceptionOnScriptError(false);
HtmlPage page = client.getPage(URL_HZW);
toLoadJS(page);
ScriptResult result = page.executeJavaScript(“toFetchEpisodes()”);
Object javaScriptResult = result.getJavaScriptResult();
System.out.println(javaScriptResult);
protected static void toLoadJS(HtmlPage page) throws IOException{
URL url = TEST.class.getResource(“/”);
String filename = url.toString() + “Core.js”;
filename = filename.replace(“file:/”, “”);
File file = new File(filename);
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] bytes = new byte[bis.available()];
bis.read(bytes);
bis.close();
String js = new String(bytes);
page.executeJavaScript(js);
}
Core.js
function toFetchEpisodes(){
var children = $(“.play-list”).children();
var contents = [];
$(children).each(function(item){
contents.push($(item).html());
});
return contents.join(“,”);
}

问一下,toLoadJS这个是啥方法,怎么没找到。

本人拆开的一个方法呀,你仔细看看!


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明问一下怎么看天猫源码的促销价
喜欢 (0)
[1034331897@qq.com]
分享 (0)