+ -
当前位置:首页 → 问答吧 → 数据采集问题:数据在JS中

数据采集问题:数据在JS中

时间:2010-09-11

来源:互联网

看了张老师的视频后,我试着去新浪一个新闻页想要采集一下,地址:tech.sina.com.cn/top/day_hotnews.shtml

我按照张老师的程序试着写了正则,输出数组发现都为空,查看源代码,才发现源代码中并没有这些信息的链接,

在显示数据的地方,只有一个这样的JS脚本:

<script>
     function showContent(data_arr){
    var html= '';
    data = data_arr['data']
    for(var i in data){
           html+='<tr>';
    html+='<td>'+(parseInt(i)+1)+'</td><td class="ConsTi"><a href="'+data.url+'" target="_blank">'+data.title+'</a></td>';
    html+='<td>'+data.top_num+'</td>';
    html+='<td>'+data.create_date+'</td>'
    html+='<td><a href="'+data.comment_url+'" target="_blank">发表评论</a></td>'
     html += '</tr>';
  }
    html+='</table></div>';
    document.write(html);
  }
</script>



也就是说,数据都是JS动态显示的,这可难住我了,求救各位大哥哥大姐姐,有什么解决思路,十分感谢

作者: php100sort   发布时间: 2010-09-11

十分抱歉,请版主删掉我的一个帖子,我不知道已经提交了,结果就提交了两个一模一样的帖子

作者: php100sort   发布时间: 2010-09-11

它每个showContent前都有一个
复制代码
  1. <script type="text/javascript" src="http://top.tech.sina.com.cn/ws/GetTopDataList.php?top_type=day&top_cat=all&top_time=20100911&top_show_num=100&top_order=ASC&js_var=all_1_data&call_back=showContent"></script>

其中的src是一个产生json的php文件,例如里面有一段数据如下:
复制代码
  1. var it_1_data = {"conf":{"js_var":"it_1_data"},"data":[{"id":"849","title":"\u5fae\u8f6fWP7\u6e38\u884c\u6d3b\u52a8\u4e3e\u884c\u846c\u793c\u5ba3\u5224iPhone\u6b7b\u5211(\u56fe)","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4645512&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/10434645512.shtml","create_date":"2010-09-11","create_time":"10:43:00","cat_name":"it","top_time":"20100911","top_num":"1","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"850","title":"\u65c5\u5ba2\u5e266\u53f0\u82f9\u679ciPad\u7535\u81111\u53f0iPhone\u8fc7\u5173\u65f6\u88ab\u67e5","media":"\u5927\u6d0b\u7f51-\u5e7f\u5dde\u65e5\u62a5","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644828&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/04204644828.shtml","create_date":"2010-09-11","create_time":"04:20:00","cat_name":"it","top_time":"20100911","top_num":"2","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"851","title":"\u82f9\u679c\u4ee3\u5de5\u4f53\u7cfb\u6084\u7136\u53d8\u9635\uff1a\u9e3f\u6d77\u4e0d\u518d\u4e00\u5bb6\u72ec\u5927","media":"21\u4e16\u7eaa\u7ecf\u6d4e\u62a5\u9053","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644745&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/03104644745.shtml","create_date":"2010-09-11","create_time":"03:10:00","cat_name":"it","top_time":"20100911","top_num":"3","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"852","title":"\u67f3\u4f20\u5fd7\uff1a\u5e0c\u671b\u8054\u60f3\u6210\u4e3a\u4e00\u4e2a\u6ca1\u6709\u5bb6\u65cf\u7684\u5bb6\u65cf\u4f01\u4e1a","media":"\u4e2d\u56fd\u5e7f\u64ad\u7f51","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4645705&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/13074645705.shtml","create_date":"2010-09-11","create_time":"13:07:00","cat_name":"it","top_time":"20100911","top_num":"4","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"853","title":"\u5f6d\u535a\u65b0\u95fb\u5468\u520a\uff1a\u5bcc\u58eb\u5eb7\u5e1d\u56fd\u52fe\u52d2\u672a\u6765","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4645597&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/12064645597.shtml","create_date":"2010-09-11","create_time":"12:06:00","cat_name":"it","top_time":"20100911","top_num":"5","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"854","title":"\u4e2d\u56fd\u79d1\u6280\u80a1\u8fdb\u5316\u8bba\uff1a\u4e00\u5f20\u8fd0\u52a8\u4e2d\u7684\u4ea7\u4e1a\u5730\u56fe","media":"21\u4e16\u7eaa\u7ecf\u6d4e\u62a5\u9053","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644742&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/03054644742.shtml","create_date":"2010-09-11","create_time":"03:05:00","cat_name":"it","top_time":"20100911","top_num":"6","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"855","title":"\u521b\u4e1a\u677f\u5468\u5e74\u56de\u671b\uff1a\u201c28\u661f\u5bbf\u201d\u5fe7\u601d\u5f55","media":"21\u4e16\u7eaa\u7ecf\u6d4e\u62a5\u9053","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644737&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/02584644737.shtml","create_date":"2010-09-11","create_time":"02:58:00","cat_name":"it","top_time":"20100911","top_num":"7","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"856","title":"\u67f3\u4f20\u5fd7\u8c08\u60e0\u666eCEO\u8f9e\u804c\uff1a\u8463\u4e8b\u4f1a\u51b3\u7b56\u592a\u8d38\u7136","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4645963&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/16014645963.shtml","create_date":"2010-09-11","create_time":"16:01:00","cat_name":"it","top_time":"20100911","top_num":"8","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"857","title":"\u5fae\u8f6f\u62df\u5168\u56fd\u590d\u5236\u6606\u660e\u6a21\u5f0f \u5411\u4e1c\u839e\u7f51\u5427\u629b\u6a44\u6984\u679d","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4639766&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-10\/00044639766.shtml","create_date":"2010-09-10","create_time":"00:04:00","cat_name":"it","top_time":"20100911","top_num":"9","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"858","title":"\u9e3f\u6d778\u6708\u8425\u6536\u8fbe455\u4ebf\u5143\u521b\u5355\u6708\u8425\u6536\u65b0\u9ad8","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4645931&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/15284645931.shtml","create_date":"2010-09-11","create_time":"15:28:00","cat_name":"it","top_time":"20100911","top_num":"10","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"859","title":"\u7231\u56fd\u8005\u603b\u88c1\u51af\u519b\u5c06\u6350\u5168\u90e8\u8d22\u4ea7","media":"\u4eac\u534e\u65f6\u62a5","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644755&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/03584644755.shtml","create_date":"2010-09-11","create_time":"03:58:00","cat_name":"it","top_time":"20100911","top_num":"11","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"860","title":"\u5404\u56fd\u521b\u4e1a\u677f\u6210\u8d25\u5bfb\u6839\uff1a\u6210\u5c31NASDAQ\u7684IT\u6d6a\u6f6e","media":"21\u4e16\u7eaa\u7ecf\u6d4e\u62a5\u9053","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644741&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/03024644741.shtml","create_date":"2010-09-11","create_time":"03:02:00","cat_name":"it","top_time":"20100911","top_num":"12","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"861","title":"IBM\u516c\u5e03\u6700\u65b0\u878d\u8d44\u8ba1\u5212 \u5c06\u63d0\u4f9b\u4ee5\u65e7\u6362\u65b0\u4fe1\u8d37","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644991&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/04364644991.shtml","create_date":"2010-09-11","create_time":"04:36:00","cat_name":"it","top_time":"20100911","top_num":"13","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"862","title":"\u5b5f\u9f0e\u94ed\u518d\u9020SAP\uff1a\u5b9e\u73b0\u51fa\u4efb\u8054\u5e2dCEO\u7684\u68a6\u60f3","media":"\u7ecf\u6d4e\u89c2\u5bdf\u62a5","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644524&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/01034644524.shtml","create_date":"2010-09-11","create_time":"01:03:00","cat_name":"it","top_time":"20100911","top_num":"14","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"863","title":"\u65b0\u5947\u7684\u8155\u4e0a\u7535\u5b50\u4ea7\u54c1\uff08\u56fe\uff09","media":"\u91d1\u7f8a\u7f51\uff0d\u65b0\u5feb\u62a5","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4645753&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/14334645753.shtml","create_date":"2010-09-11","create_time":"14:33:00","cat_name":"it","top_time":"20100911","top_num":"15","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"864","title":"\u5916\u5a92\u8be6\u89e3\u82f9\u679c\u89e3\u9664\u5e94\u7528\u5f00\u53d1\u7981\u4ee4\u4e4b\u5f71\u54cd","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644679&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/01234644679.shtml","create_date":"2010-09-11","create_time":"01:23:00","cat_name":"it","top_time":"20100911","top_num":"16","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"865","title":"\u4e09\u8054\u751f\u6d3b\u5468\u520a\uff1a\u8054\u60f3\u5168\u7403\u62d3\u5c55\u53f2","media":"\u4e09\u8054\u751f\u6d3b\u5468\u520a","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4643552&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-10\/16024643552.shtml","create_date":"2010-09-10","create_time":"16:02:00","cat_name":"it","top_time":"20100911","top_num":"17","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"866","title":"\u9c8d\u5c14\u9ed8\uff1a\u671f\u5f85\u57c3\u6d1b\u666e\u5c31\u4efb\u8bfa\u57fa\u4e9aCEO\u540e\u7ee7\u7eed\u5408\u4f5c","media":"\u65b0\u6d6a\u79d1\u6280","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4643446&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-10\/15244643446.shtml","create_date":"2010-09-10","create_time":"15:24:00","cat_name":"it","top_time":"20100911","top_num":"18","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"867","title":"\u79d1\u6280\u52c3\u5174\uff1a\u770b\u8d44\u672c\u7684\u8138\u8272 \u8fd8\u662f\u770b\u4ea7\u4e1a\u7684\u6210\u8272","media":"21\u4e16\u7eaa\u7ecf\u6d4e\u62a5\u9053","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644740&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/03004644740.shtml","create_date":"2010-09-11","create_time":"03:00:00","cat_name":"it","top_time":"20100911","top_num":"19","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""},{"id":"868","title":"\u89c6\u89c9\u65b0\u7eaa\u5143\u7684\u5f00\u542f\uff1a\u4ece\u4e8c\u7ef4\u5230\u4e09\u7ef4\u7684\u8df3\u8dc3","media":"\u7ecf\u6d4e\u89c2\u5bdf\u62a5","author":"it","comment_url":"http:\/\/comment4.news.sina.com.cn\/comment\/comment4.html?channel=kj&newsid=2-1-4644537&style=0","url":"http:\/\/tech.sina.com.cn\/it\/2010-09-11\/01234644537.shtml","create_date":"2010-09-11","create_time":"01:23:00","cat_name":"it","top_time":"20100911","top_num":"20","ext1":"False","ext2":"","ext3":"","ext4":"","ext5":""}]};
  2. if ( typeof(showContent) != "undefined" ){showContent(it_1_data);}

可以通过使用这个php文件生成的json来获取其中的新闻连接和内容~不妨试试吧~

作者: anjingyu_ws   发布时间: 2010-09-11

作者: kuaiman1   发布时间: 2010-09-11

相关阅读 更多