找回密码
 加入
搜索
查看: 11911|回复: 15

[网络通信] 请教:这种的网络文章采集源码怎么写

 火.. [复制链接]
发表于 2012-10-15 01:10:19 | 显示全部楼层 |阅读模式
本帖最后由 d12990 于 2012-10-20 15:06 编辑

程序要实现的功能大概是这样,打开某个页面地址,比如:  http://finance.china.com.cn/news/gnjj/index.shtml

     里面有很多新闻文章,想把每一条新闻都采集下来,并且以TXT 文本保存到本机电脑某个文件夹里,每个文章的文本就以这篇文章的标题命名 , 这个页面采完了,会自动点击下一页面继续采集,直到最后一页为止。程序最好是可以自己输入需要采集的页面地址,这样通用性会比较好.... 不要把这个地址嵌在源码里

   大致功能就是这些。
你们说多少钱
发表于 2012-10-15 07:48:31 | 显示全部楼层
连不想搜索连不看帮助文件 都如此的说出来 估计木有人会帮你这样的人
发表于 2012-10-15 08:02:17 | 显示全部楼层
别说几天 甚至数月数年 刻苦的人都有
发表于 2012-10-15 10:33:20 | 显示全部楼层
本帖最后由 shqf 于 2012-10-15 10:35 编辑

还是搜索一下吧,你所需的代码基本能找到。只是不同的网页,源码不同,你的通用性要求恐怕较难实现。
发表于 2012-10-15 10:44:21 | 显示全部楼层
回复 1# d12990
自己学着写一次,遇到问题就问,别人会尽量帮的,直接要代码不太好
这个不是很难我可以告诉你具体怎么做
1、在这个网页的第一页能取到下面的内容
            <li><span>2012-10-15 10:08</span><a href="http://finance.china.com.cn/news/special/jjsj9/20121015/1068512.shtml" target="_blank">统计局:9月份住房租金价格同比上涨3.2%</a></li>
<li><span>2012-10-15 09:49</span><a href="http://finance.china.com.cn/news/special/jjsj9/20121015/1068475.shtml" target="_blank">统计局:9月份居民消费价格总水平同比涨1.9%</a></li>
<li><span>2012-10-15 09:44</span><a href="http://finance.china.com.cn/news/special/jjsj9/20121015/1068472.shtml" target="_blank">国家统计局:9月份PPI同比下降3.6%</a></li>
<li><span>2012-10-15 09:36</span><a href="http://finance.china.com.cn/news/special/jjsj9/20121015/1068416.shtml" target="_blank">快讯:9月份中国CPI同比上涨1.9%</a></li>
<li><span>2012-10-15 08:45</span><a href="http://finance.china.com.cn/news/special/jjsj9/20121015/1068166.shtml" target="_blank">统计局公布50城食品价格变动 大白菜十天降11%</a></li>
<li><span>2012-10-15 07:49</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1067983.shtml" target="_blank">中小企业投资信心指数骤降22%</a></li>
<li><span>2012-10-15 07:24</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1067891.shtml" target="_blank">前9月外贸增长6.2% 9月出口增长9.9%创新高</a></li>
<li><span>2012-10-15 07:08</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1067876.shtml" target="_blank">货币增速创出年内新高 稳增长政策发挥作用</a></li>
<li><span>2012-10-15 04:10</span><a href="http://finance.china.com.cn/roll/20121015/1067733.shtml" target="_blank">10月上旬食品价格涨幅缩小 价格总体平稳</a></li>
<li><span>2012-10-15 02:30</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1067461.shtml" target="_blank">海关总署:9月份出口增长9.9% 创历史新高</a></li>
<li><span>2012-10-15 01:00</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1067308.shtml" target="_blank">央行:三季度我国外汇储备恢复正增长</a></li>
<li><span>2012-10-15 01:00</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1067307.shtml" target="_blank">央行:9月份广义货币增长14.8% 达年内新高</a></li>
<li><span>2012-10-15 00:30</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1067038.shtml" target="_blank">多项数据回暖释放经济筑底企稳信号</a></li>
<li><span>2012-10-15 00:29</span><a href="http://finance.china.com.cn/news/special/jjsj9/20121015/1066981.shtml" target="_blank">9月中国出口创单月新高 稳外贸政策初见成效</a></li>
<li><span>2012-10-15 00:29</span><a href="http://finance.china.com.cn/news/gnjj/20121015/1066964.shtml" target="_blank">第112届广交会今开幕 预计成交态势不乐观</a></li>
<li><span>2012-10-15 00:09</span><a href="http://finance.china.com.cn/news/special/jjsj9/20121015/1066962.shtml" target="_blank">9月经济数据今日公布 四季度降息预期升温</a></li>
<li><span>2012-10-14 19:49</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066947.shtml" target="_blank">9月下旬以来全国鸡蛋价格下降近5%</a></li>
<li><span>2012-10-14 18:28</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066941.shtml" target="_blank">长沙曝光26家地沟油“黑作坊”名单</a></li>
<li><span>2012-10-14 16:41</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066923.shtml" target="_blank">三季度我国外储恢复正增长 未来或平稳中小幅波动</a></li>
<li><span>2012-10-14 16:05</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066918.shtml" target="_blank">广交会遭遇外贸寒冬 “国八条”成效待检</a></li>
<li><span>2012-10-14 14:44</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066902.shtml" target="_blank">货币增速创年内新高显示中国稳增长政策发挥作用</a></li>
<li><span>2012-10-14 11:18</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066875.shtml" target="_blank">乍暖还寒:“富豪榜单”测试中国民营经济“温度”</a></li>
<li><span>2012-10-14 11:16</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066874.shtml" target="_blank">海南楼市9月量价温和下调</a></li>
<li><span>2012-10-14 10:16</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066859.shtml" target="_blank">9月货币增速创年内新高 央行称四季度经济望回暖</a></li>
<li><span>2012-10-14 09:14</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066844.shtml" target="_blank">央行8月外汇占款现净增长 或为未下调存准原因</a></li>
<li><span>2012-10-14 08:55</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066840.shtml" target="_blank">中国社科院预计:今年GDP增长约7.7%明年8.2%</a></li>
<li><span>2012-10-14 07:44</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066782.shtml" target="_blank">北京工商被曝光索要关系费 企业称有电话录音</a></li>
<li><span>2012-10-14 07:19</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066754.shtml" target="_blank">北京鼓励民间资本参与养老 力争床位达12万张</a></li>
<li><span>2012-10-14 07:17</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066752.shtml" target="_blank">9月CPI明日公布 机构预计年内物价不会大幅反弹</a></li>
<li><span>2012-10-14 07:16</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066751.shtml" target="_blank">9月单月出口规模创历史新高 中日双边贸易下降1.8%</a></li>
<li><span>2012-10-14 05:59</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066722.shtml" target="_blank">9月末我国外汇储备余额3.29万亿美元</a></li>
<li><span>2012-10-14 05:59</span><a href="http://finance.china.com.cn/news/gnjj/20121014/1066713.shtml" target="_blank">外贸稳增长政策效应逐渐释放</a></li>
<li><span>2012-10-13 23:22</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1066644.shtml" target="_blank">中国外贸增速预计低位趋稳 年度目标恐难实现</a></li>
<li><span>2012-10-13 19:24</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1066630.shtml" target="_blank">分析指季节性因素致中国9月出口数据超预期</a></li>
<li><span>2012-10-13 17:55</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1066617.shtml" target="_blank">10月份以来近八成省区市猪肉价格下降</a></li>
<li><span>2012-10-13 17:02</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1066612.shtml" target="_blank">央行:截至9月末广义货币增长14.8%</a></li>
<li><span>2012-10-13 16:58</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1066609.shtml" target="_blank">圣诞季推动外贸回升 中日双边贸易总值下降</a></li>
<li><span>2012-10-13 16:58</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1066610.shtml" target="_blank">出口反弹走出低谷 “稳外贸”政策提振信心</a></li>
<li><span>2012-10-13 02:30</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1065998.shtml" target="_blank">央行:9月社会融资规模1.65万亿 环比增4041亿</a></li>
<li><span>2012-10-13 01:43</span><a href="http://finance.china.com.cn/news/gnjj/20121013/1065966.shtml" target="_blank">温家宝:宁肯少上项目也要确保养老保险投入</a></li>
<li><span>2012-10-12 20:04</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065701.shtml" target="_blank">9月份信贷增长低于预期 贷款投放节奏更趋均衡</a></li>
<li><span>2012-10-12 16:36</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065626.shtml" target="_blank">世界航空巨头逆市增开中国航线</a></li>
<li><span>2012-10-12 16:21</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065588.shtml" target="_blank">央行报告:前三季度社会融资规模11.73万亿元</a></li>
<li><span>2012-10-12 15:57</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065580.shtml" target="_blank">财政部与国际农发基金签约扶持湖南农村发展</a></li>
<li><span>2012-10-12 15:57</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065581.shtml" target="_blank">前9个月全国保障房新开工720万套</a></li>
<li><span>2012-10-12 15:47</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065537.shtml" target="_blank">财政部与国际农发基金签署4600万美元贷款协定</a></li>
<li><span>2012-10-12 15:26</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065348.shtml" target="_blank">第十届全国投资促进机构联席会议在渝召开</a></li>
<li><span>2012-10-12 15:11</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065316.shtml" target="_blank">第九届城市友好商会经济协作会举行</a></li>
<li><span>2012-10-12 14:57</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065586.shtml" target="_blank">外需下滑成“硬伤” 政策出台护力转型升级</a></li>
<li><span>2012-10-12 14:49</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065568.shtml" target="_blank">中国延长对进口氨纶反倾销措施的实施期限</a></li>
<li><span>2012-10-12 14:49</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065283.shtml" target="_blank">国务院正式批复广州南沙新区发展规划</a></li>
<li><span>2012-10-12 10:44</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1064925.shtml" target="_blank">国家电监会:9月份全国电力供需总体平衡</a></li>
<li><span>2012-10-12 10:39</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1065149.shtml" target="_blank">中国经济简讯:2012哈尔滨世界农业博览会开幕</a></li>
<li><span>2012-10-12 10:34</span><a href="http://finance.china.com.cn/roll/20121012/1064864.shtml" target="_blank">全国鸡蛋价格降速加快 食用油价格上涨</a></li>
<li><span>2012-10-12 10:33</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1064824.shtml" target="_blank">国土资源部:基本农田示范县建设提速</a></li>
<li><span>2012-10-12 10:29</span><a href="http://finance.china.com.cn/roll/20121012/1064777.shtml" target="_blank">欧盟公布对华光伏反倾销调查名单</a></li>
<li><span>2012-10-12 10:29</span><a href="http://finance.china.com.cn/roll/20121012/1064790.shtml" target="_blank">光伏案终裁 企业或可借“漏洞”海外设厂</a></li>
<li><span>2012-10-12 10:29</span><a href="http://finance.china.com.cn/roll/20121012/1064786.shtml" target="_blank">双反制裁倒逼中国企业苦练“内功”</a></li>
<li><span>2012-10-12 09:58</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1064700.shtml" target="_blank">下游需求未改善 “煤”飞遭遇天花板</a></li>
<li><span>2012-10-12 09:54</span><a href="http://finance.china.com.cn/news/gnjj/20121012/1064696.shtml" target="_blank">财政部:中央财政提前下达2013年低保预算696亿</a></li>
从里面能得到你想要的所有文章的链接跟文章的名字
2、在每分页的里面文章的主体都在
<div class="tex" id="content">
<p align=center>
之间取出来就可以
3、因为取出来的内容里面是网页代码,再把</p><p> 处理一下就可以了
发表于 2012-10-15 12:25:27 | 显示全部楼层
本帖最后由 love5173 于 2012-10-15 12:34 编辑

这是个取第一个文章的例子
#include <INet.au3>
Dim $url="http://finance.china.com.cn/news/gnjj/index.shtml"
$sString = InetRead($URL, 1)
$sss=BinaryToString($sString,4)
$array=StringRegExp($sss,'</span><a href="(.*?)" target="_blank">(.*?)</a>',3)
$sString = InetRead($array[0], 1)
$str=BinaryToString($sString,4)
$str=StringRegExp($str,'(?s)<div class="tex" id="content">(.*?)<p align',3)
$last=StringRegExpReplace($str[0],'</p>|<p>|\h+',"")
MsgBox(0,$array[1],$last)
 楼主| 发表于 2012-10-15 15:04:43 | 显示全部楼层
楼上的兄弟:能不能给个完整代码,我回头好好研究下,多谢
发表于 2012-10-15 19:32:15 | 显示全部楼层
回复 7# d12990
我给的就是 从你给的那个网页开始到取到第一篇帖子的过程啊,知道第一个了,后面的还不好说么
 楼主| 发表于 2012-10-15 20:11:16 | 显示全部楼层
本帖最后由 d12990 于 2012-10-15 20:14 编辑

兄弟:你就给个完整 的好了,我看了一下帮助文件,像看天书一样,不懂啊

还有你这个代码还是把地址放在源码里,如果换个采集的地址,可能就不灵了,又要修改,能不能搞个输入框的,兄弟能否改进下
发表于 2012-10-16 22:10:12 | 显示全部楼层
回复 9# d12990
我看你纯粹是个伸手党,想不劳而获,还说研究了几个晚上死了多少脑细胞,纯粹是扯淡。
6楼已经把关键的代码写给你了,只要加个简简单单的GUI和Filewrite就行了,你还不满足。
如果你真的需要全部源码,给我50块钱,我让你省心怎么样?
 楼主| 发表于 2012-10-17 00:31:45 | 显示全部楼层
本帖最后由 d12990 于 2012-10-17 00:33 编辑

楼上的兄弟:50 可以的: 你QQ  多少
这个单给你,淘宝交易,我也懒得发帖了
发表于 2012-10-17 07:32:03 | 显示全部楼层
我晕,这样也行!
发表于 2012-10-17 23:05:22 | 显示全部楼层
回复 6# love5173
这个网站好像通过地址栏输入第x页的网址却不能打开,这样要采集下一页的内容比较麻烦了,不知道有没有什么好的办法?
发表于 2012-10-19 16:57:05 | 显示全部楼层
本帖最后由 love5173 于 2012-10-19 16:58 编辑

回复 13# xms77
你打开第二页 再看看URL 就知道了,是有序号的。一直取到取不到内容为止
http://app.finance.china.com.cn/news/column.php?cname=%E5%9B%BD%E5%86%85%E7%BB%8F%E6%B5%8E&p=2
看到没有,第一页没序号但是后面都有
发表于 2012-10-19 23:27:02 | 显示全部楼层
回复 14# love5173
果然是这样,我用这个就不行。
http://app.finance.china.com.cn/news/column.php?cname=国内经济&p=4
[
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-3 12:52 , Processed in 0.087998 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表