新手求教怎么抓取这个网页里这几个表格的数据,实在晕了。。。。

qq_29028741 2015-08-26 01:30:36
想抓取这个网页里A类 ,B类,母基。。。母基可交易分级,这里面的表格里的数据,然后转到EXCEL里

http://www.jisilu.cn/data/sfnew/#tlink_3

然后发觉,那几张 table 都是用动态生成的。。。直接抓取HTML源码不行。。。。

对这方面完全不会,查了挺久资料后,貌似可以用SELENIUM和PHANTOMJS来得到,加载完成后的网页代码

于是,我就打算先用CHROME来学习下SELENIUM怎么用,写了段简单代码

结果发觉,还是得不到CHROME浏览器按F12,ELEMENTS里面的完整内容啊。。。。。求教

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.*;

public class test1 {

public static void testSelenium() {
System.getProperties().setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
webDriver.get("http://www.jisilu.cn/data/sfnew/#tlink_3");
System.out.println(webDriver.getPageSource());
webDriver.close();
}
}
...全文
411 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
tony4geek 2015-08-27
  • 打赏
  • 举报
回复
引用 13 楼 sgwen20 的回复:
[quote=引用 12 楼 rui888 的回复:] 你浏览器调试看看,能不能找到请求的url 入口。肯定有个url 请求后台的数据。 饭后分析者个url 请求返回的数据。具体行不行,不知道。
here: http://www.jisilu.cn/data/sfnew/funda_list/?___t=1440582005933 http://www.jisilu.cn/data/sfnew/fundb_list/?___t=1440582005933 http://www.jisilu.cn/data/sfnew/fundm_list/?___t=1440582005933[/quote] 去 http://www.jisilu.cn/static/js/simpleTableBuilder.js?v=20150724 里面看,数据都在这里。
a_b_a_b_a_b_a_b 2015-08-27
  • 打赏
  • 举报
回复
你是后台获取还是可以在js获取呢?页面加载完成后调用js不行吗?后台的话用jsoup就可以吧。
qq_30857701 2015-08-27
  • 打赏
  • 举报
回复
引用 14 楼 a_b_a_b_a_b_a_b 的回复:
你是后台获取还是可以在js获取呢?页面加载完成后调用js不行吗?后台的话用jsoup就可以吧。
做作业临时开始学的。。。了解极浅啊。。 我现在是看了JS源码后,直接向里面获得数据的URL发请求,然后处理返回的JSON数据
qq_29028741 2015-08-27
  • 打赏
  • 举报
回复
引用 13 楼 sgwen20 的回复:
[quote=引用 12 楼 rui888 的回复:] 你浏览器调试看看,能不能找到请求的url 入口。肯定有个url 请求后台的数据。 饭后分析者个url 请求返回的数据。具体行不行,不知道。
here: http://www.jisilu.cn/data/sfnew/funda_list/?___t=1440582005933 http://www.jisilu.cn/data/sfnew/fundb_list/?___t=1440582005933 http://www.jisilu.cn/data/sfnew/fundm_list/?___t=1440582005933[/quote] 嗯。。。再查了一轮资料发现这个貌似不能直接抓取拼接好的网页代码,现在已经改为用这些URL请求JSON数据,然后处理的方法了
shiguowen 2015-08-26
  • 打赏
  • 举报
回复
引用 12 楼 rui888 的回复:
你浏览器调试看看,能不能找到请求的url 入口。肯定有个url 请求后台的数据。 饭后分析者个url 请求返回的数据。具体行不行,不知道。
here: http://www.jisilu.cn/data/sfnew/funda_list/?___t=1440582005933 http://www.jisilu.cn/data/sfnew/fundb_list/?___t=1440582005933 http://www.jisilu.cn/data/sfnew/fundm_list/?___t=1440582005933
tony4geek 2015-08-26
  • 打赏
  • 举报
回复
你浏览器调试看看,能不能找到请求的url 入口。肯定有个url 请求后台的数据。 饭后分析者个url 请求返回的数据。具体行不行,不知道。
qq_30857701 2015-08-26
  • 打赏
  • 举报
回复
引用 10 楼 rui888 的回复:
引用 9 楼 shijing266 的回复:
[quote=引用 8 楼 rui888 的回复:] - -! 你页面加载完了,不就是静态的啦
他那个数据画面没有的,是js 生成的,就是为了防止数据被抓取的,其次还有就是实时性显示。 这种情况就得模拟浏览器的动作执行。jsoup 类的框架是抓取最后生成的静态html 文件。
那不就是取后台数据一样了? [/quote]

function showFundA(){
	if(!tableFundA){
		tableFundA = new SimpleTableBuilder({
			tid: 'flex3',
			rp: 50,
			async:false,
			dataURL: '/data/sfnew/funda_list/',
			title: '#tableFundATitle',
			cols: [
			{display: '代码', title:'A类代码', name : 'funda_id', width : 35,nowrap:true,
				link: {
					url:'data/sfnew/detail/{{funda_id}}',
					newpage: true,
					type: self
				}
			},
			{display: '名称', title:'A类名称', name : 'funda_name', width : 40,nowrap:true,formatter:sfFundNameFormatter},
			{display: '现价', title:'A类现价', name : 'funda_current_price', width : 35, tooltip:'最后更新时间:{{last_time}}',nowrap:true,
				link: {
					url:'http://finance.sina.com.cn/fund/quotes/{{funda_id}}/bc.shtml',
					newpage: true,
					type: self
				}
			},
			{display: '涨幅', title:'A类涨幅', name : 'funda_increase_rt', width : 35, color:true,nowrap:true},
			{display: '成交额<br>(万元)', title:'A类成交金额', name : 'funda_volume', width : 35,nowrap:true},
			{display: '净值', title:'A类净值', name : 'funda_value', width : 35,tooltip:'净值日期:{{funda_nav_dt}}',nowrap:true,
				link: {
					newpage: true,
					url: 'http://www.cninfo.com.cn/information/fund/netvalue/{{funda_id}}.html',
					type: 'self'
				}
			},
			{display: '折价率', title:'A类折价率', name : 'funda_discount_rt', width : 30,nowrap:true},
      {display: '利率<br>规则', name : 'coupon_descr_s', tooltip:'利率规则说明:{{coupon_descr}}', width : 35,nowrap:true},
			{display: '本期<br>利率', name : 'funda_coupon', width : 35,nowrap:true},
			{display: '下期<br>利率', name : 'funda_coupon_next', width : 35, bgcolor:"yellow",nowrap:true},
			{display: '修正<br>收益率', title: '修正收益率', name : 'funda_profit_rt_next', width : 35, bgcolor:"yellow",nowrap:true},
			{display: '剩余<br>年限', name : 'funda_left_year', width : 30, sorter : 'leftYear',nowrap:true},
			{display: '参考指数', name : 'funda_index_name', width : 35, nowrap:true,formatter:sfIndexNameFormatter},
			{display: '参考指数id', name : 'funda_index_id', hidden:true},
			{display: '指数<br>涨幅', name : 'funda_index_increase_rt', width : 35, color:true,nowrap:true},
			{display: '下折<br>母基需跌', title:'下折母基需跌', name : 'funda_lower_recalc_rt', width : 35, nowrap:true,formatter:sflowerRecalcFormatter, sorter:'percentSorter'},
			{display: '理论<br>下折收益', title:'注意:参与下折也存在风险!', name : 'lower_recalc_profit_rt', width : 35, nowrap:true, bgcolor:"yellow"},
      {display: '上折<br>母基需涨', title:'上折母基需涨', name : 'fundb_upper_recalc_rt', width : 35, nowrap:true,formatter:upperRecalcFormatter, sorter:'percentSorter'},
			{display: '整体<br>溢价率', name : 'funda_base_est_dis_rt', width : 35,  bgcolor:"yellow",nowrap:true,tooltip:'{{funda_base_est_dis_rt_tip}}'},
      {display: 'T-1<br>溢价率', title:'T-1日整体溢价率', name : 'funda_base_est_dis_rt_t1', width : 35,nowrap:true},
      {display: 'T-2<br>溢价率', title:'T-2日整体溢价率', name : 'funda_base_est_dis_rt_t2', width : 35,nowrap:true},
			{display: 'A份额<br>(万份)', title:'A类份额', name : 'funda_amount', width : 35,nowrap:true},
			{display: 'A新增<br>(万份)', title:'A类新增份额', name : 'funda_amount_increase', tooltip:'A份额增长{{funda_amount_increase_rt}}', width : 35, bgcolor:"yellow",nowrap:true},
			{display: 'A:B', name : 'abrate', width : 30,nowrap:true},
			{display: '净值日期', name: 'funda_nav_dt', hidden: true},
			{display: '最后更新', name: 'last_time', hidden: true},
      {display: '利率规则说明', name: 'coupon_descr', hidden: true},
			{display: '下次定折', name: 'next_recalc_dt', width: 100, tooltip:'定折说明:{{fund_descr}}', nowrap:true, sorter:'recalcDateSorter'},
			{display: '定期折算', name: 'fund_descr', width: 120, hidden: true},
      {display: 'A份额增长', name: 'funda_amount_increase_rt', width: 10, hidden: true},
      {display: '溢价率提示信息', name: 'funda_base_est_dis_rt_tip', width: 40, hidden: true},
			{display: '操作', name: 'fundaOpt', formatter: fundaOptFormatter, width:10}
			]
		});
		tableFundA.show($('#fundASearchForm').serializeObjectToJson());
		autoReloadFundATable(tableFundA,'auto_reload_funda','auto_reload_funda');
	}else{
		doFundASearch();
	}
};
数据这里展示的 A类 tableFundA.show($('#fundASearchForm').serializeObjectToJson()); autoReloadFundATable(tableFundA,'auto_reload_funda','auto_reload_funda');[/quote] 。。。。对了,是这里生成的。不过没学过JS,找到但不会搞啊。。。
tony4geek 2015-08-26
  • 打赏
  • 举报
回复
引用 9 楼 shijing266 的回复:
引用 8 楼 rui888 的回复:
- -! 你页面加载完了,不就是静态的啦
他那个数据画面没有的,是js 生成的,就是为了防止数据被抓取的,其次还有就是实时性显示。 这种情况就得模拟浏览器的动作执行。jsoup 类的框架是抓取最后生成的静态html 文件。
那不就是取后台数据一样了? [/quote]

function showFundA(){
	if(!tableFundA){
		tableFundA = new SimpleTableBuilder({
			tid: 'flex3',
			rp: 50,
			async:false,
			dataURL: '/data/sfnew/funda_list/',
			title: '#tableFundATitle',
			cols: [
			{display: '代码', title:'A类代码', name : 'funda_id', width : 35,nowrap:true,
				link: {
					url:'data/sfnew/detail/{{funda_id}}',
					newpage: true,
					type: self
				}
			},
			{display: '名称', title:'A类名称', name : 'funda_name', width : 40,nowrap:true,formatter:sfFundNameFormatter},
			{display: '现价', title:'A类现价', name : 'funda_current_price', width : 35, tooltip:'最后更新时间:{{last_time}}',nowrap:true,
				link: {
					url:'http://finance.sina.com.cn/fund/quotes/{{funda_id}}/bc.shtml',
					newpage: true,
					type: self
				}
			},
			{display: '涨幅', title:'A类涨幅', name : 'funda_increase_rt', width : 35, color:true,nowrap:true},
			{display: '成交额<br>(万元)', title:'A类成交金额', name : 'funda_volume', width : 35,nowrap:true},
			{display: '净值', title:'A类净值', name : 'funda_value', width : 35,tooltip:'净值日期:{{funda_nav_dt}}',nowrap:true,
				link: {
					newpage: true,
					url: 'http://www.cninfo.com.cn/information/fund/netvalue/{{funda_id}}.html',
					type: 'self'
				}
			},
			{display: '折价率', title:'A类折价率', name : 'funda_discount_rt', width : 30,nowrap:true},
      {display: '利率<br>规则', name : 'coupon_descr_s', tooltip:'利率规则说明:{{coupon_descr}}', width : 35,nowrap:true},
			{display: '本期<br>利率', name : 'funda_coupon', width : 35,nowrap:true},
			{display: '下期<br>利率', name : 'funda_coupon_next', width : 35, bgcolor:"yellow",nowrap:true},
			{display: '修正<br>收益率', title: '修正收益率', name : 'funda_profit_rt_next', width : 35, bgcolor:"yellow",nowrap:true},
			{display: '剩余<br>年限', name : 'funda_left_year', width : 30, sorter : 'leftYear',nowrap:true},
			{display: '参考指数', name : 'funda_index_name', width : 35, nowrap:true,formatter:sfIndexNameFormatter},
			{display: '参考指数id', name : 'funda_index_id', hidden:true},
			{display: '指数<br>涨幅', name : 'funda_index_increase_rt', width : 35, color:true,nowrap:true},
			{display: '下折<br>母基需跌', title:'下折母基需跌', name : 'funda_lower_recalc_rt', width : 35, nowrap:true,formatter:sflowerRecalcFormatter, sorter:'percentSorter'},
			{display: '理论<br>下折收益', title:'注意:参与下折也存在风险!', name : 'lower_recalc_profit_rt', width : 35, nowrap:true, bgcolor:"yellow"},
      {display: '上折<br>母基需涨', title:'上折母基需涨', name : 'fundb_upper_recalc_rt', width : 35, nowrap:true,formatter:upperRecalcFormatter, sorter:'percentSorter'},
			{display: '整体<br>溢价率', name : 'funda_base_est_dis_rt', width : 35,  bgcolor:"yellow",nowrap:true,tooltip:'{{funda_base_est_dis_rt_tip}}'},
      {display: 'T-1<br>溢价率', title:'T-1日整体溢价率', name : 'funda_base_est_dis_rt_t1', width : 35,nowrap:true},
      {display: 'T-2<br>溢价率', title:'T-2日整体溢价率', name : 'funda_base_est_dis_rt_t2', width : 35,nowrap:true},
			{display: 'A份额<br>(万份)', title:'A类份额', name : 'funda_amount', width : 35,nowrap:true},
			{display: 'A新增<br>(万份)', title:'A类新增份额', name : 'funda_amount_increase', tooltip:'A份额增长{{funda_amount_increase_rt}}', width : 35, bgcolor:"yellow",nowrap:true},
			{display: 'A:B', name : 'abrate', width : 30,nowrap:true},
			{display: '净值日期', name: 'funda_nav_dt', hidden: true},
			{display: '最后更新', name: 'last_time', hidden: true},
      {display: '利率规则说明', name: 'coupon_descr', hidden: true},
			{display: '下次定折', name: 'next_recalc_dt', width: 100, tooltip:'定折说明:{{fund_descr}}', nowrap:true, sorter:'recalcDateSorter'},
			{display: '定期折算', name: 'fund_descr', width: 120, hidden: true},
      {display: 'A份额增长', name: 'funda_amount_increase_rt', width: 10, hidden: true},
      {display: '溢价率提示信息', name: 'funda_base_est_dis_rt_tip', width: 40, hidden: true},
			{display: '操作', name: 'fundaOpt', formatter: fundaOptFormatter, width:10}
			]
		});
		tableFundA.show($('#fundASearchForm').serializeObjectToJson());
		autoReloadFundATable(tableFundA,'auto_reload_funda','auto_reload_funda');
	}else{
		doFundASearch();
	}
};
数据这里展示的 A类 tableFundA.show($('#fundASearchForm').serializeObjectToJson()); autoReloadFundATable(tableFundA,'auto_reload_funda','auto_reload_funda');
  • 打赏
  • 举报
回复
引用 8 楼 rui888 的回复:
- -! 你页面加载完了,不就是静态的啦
他那个数据画面没有的,是js 生成的,就是为了防止数据被抓取的,其次还有就是实时性显示。 这种情况就得模拟浏览器的动作执行。jsoup 类的框架是抓取最后生成的静态html 文件。[/quote] 那不就是取后台数据一样了?
tony4geek 2015-08-26
  • 打赏
  • 举报
回复
引用 5 楼 shijing266 的回复:
[quote=引用 4 楼 qq_30857701 的回复:] [quote=引用 1 楼 shijing266 的回复:] 看看 或者用这个
这个查资料的时候看过,好像是抓静态的吧,我是想抓JS运行完之后的网页代码,就是CHROME按F12后,ELEMENTS里面的完整内容BP[/quote] - -! 你页面加载完了,不就是静态的啦[/quote]他那个数据画面没有的,是js 生成的,就是为了防止数据被抓取的,其次还有就是实时性显示。 这种情况就得模拟浏览器的动作执行。jsoup 类的框架是抓取最后生成的静态html 文件。
qq_30857701 2015-08-26
  • 打赏
  • 举报
回复
引用 5 楼 shijing266 的回复:
[quote=引用 4 楼 qq_30857701 的回复:] [quote=引用 1 楼 shijing266 的回复:] 看看 或者用这个
这个查资料的时候看过,好像是抓静态的吧,我是想抓JS运行完之后的网页代码,就是CHROME按F12后,ELEMENTS里面的完整内容BP[/quote] - -! 你页面加载完了,不就是静态的啦[/quote] = = 做作业临时接触的。。。。现在就是还不懂,怎么获得加载完之后的页面
qq_30857701 2015-08-26
  • 打赏
  • 举报
回复
引用 2 楼 rui888 的回复:
[quote=引用 1 楼 shijing266 的回复:] 看看 或者用这个
动态的网页画面的源代码并没有生成,是js 拼接出来的。自己写解析。[/quote] 。。。做作业才临时接触这个的。所以我是想找点工具来获得JS运行完,拼接完之后的网页代码
  • 打赏
  • 举报
回复
引用 4 楼 qq_30857701 的回复:
[quote=引用 1 楼 shijing266 的回复:] 看看 或者用这个
这个查资料的时候看过,好像是抓静态的吧,我是想抓JS运行完之后的网页代码,就是CHROME按F12后,ELEMENTS里面的完整内容BP[/quote] - -! 你页面加载完了,不就是静态的啦
qq_30857701 2015-08-26
  • 打赏
  • 举报
回复
引用 1 楼 shijing266 的回复:
看看 或者用这个
这个查资料的时候看过,好像是抓静态的吧,我是想抓JS运行完之后的网页代码,就是CHROME按F12后,ELEMENTS里面的完整内容BP
tony4geek 2015-08-26
  • 打赏
  • 举报
回复
http://bbs.csdn.net/topics/390752545
tony4geek 2015-08-26
  • 打赏
  • 举报
回复
引用 1 楼 shijing266 的回复:
看看 或者用这个
动态的网页画面的源代码并没有生成,是js 拼接出来的。自己写解析。
  • 打赏
  • 举报
回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧