楼主: air320322
12314 15

[有偿编程] 定时自动抓取网页数据 [推广有奖]

  • 4关注
  • 0粉丝

讲师

81%

还不是VIP/贵宾

-

威望
0
论坛币
11520 个
通用积分
9.5113
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
3826 点
帖子
241
精华
0
在线时间
989 小时
注册时间
2005-5-28
最后登录
2025-10-12

楼主
air320322 发表于 2012-3-5 17:06:29 |AI写论文
200论坛币
数据来源

http://www.chinaclear.cn/main/03/0303/030305/1330417819770.htm


数据会每周变动一次,能否让SAS在服务器自动运行,每周一上午9点自动读取网页数据到SAS中?

最佳答案

leptonyu 查看完整内容

data _null_; length value $32766; infile "http://www.chinaclear.cn/main/03/0303/030305/1330417819770.htm" url lrecl=1024; if _n_=1 then do; value=''; reg=prxparse('/=.*?(\d{1,3}(,\d{3})*(\.\d+)?)\s*$/'); end; input ; value=prxchange('s/(]*>|&[a-z]+;|\t+|show.*;|= \d \\\* GB3)//',-1,trimn(value)||trimn(_infile_)); if not prxmatch('/]*$|\\\#\s*$/',value) then do; if compress(v ...
关键词:抓取网页数据 China HTTP 自动运行 Main 数据 服务器 网页

本帖被以下文库推荐

不明真相的群众

沙发
leptonyu 发表于 2012-3-5 17:06:30
data _null_;
        length value $32766;
        infile "http://www.chinaclear.cn/main/03/0303/030305/1330417819770.htm" url lrecl=1024;
        if _n_=1 then do;
                value='';
                reg=prxparse('/=.*?(\d{1,3}(,\d{3})*(\.\d+)?)\s*$/');
        end;
        input ;
        value=prxchange('s/(<[^>]*>|&[a-z]+;|\t+|show.*;|= \d \\\* GB3)//',-1,trimn(value)||trimn(_infile_));
        if not prxmatch('/<[^>]*$|\\\#\s*$/',value) then do;
                if compress(value) ne '' then do;
                        if prxmatch(reg,value) then do
                                value=prxposn(reg,1,value);
                        end;
                        put value;
                end;
                value='';
        end;
        retain value reg;
run;
抓取了里面的信息,可以保存到文件,再使用导入整理,抓取结果如下

中国证券登记结算有限责任公司
一周股票账户情况统计表(2012.02.20-2012.02.24)
上海分公司
深圳分公司
合计
一、期末有效账户数(万户)
6,748.94
6,841.17
13,590.11
二、新增股票账户数(户)
116,711
103,716
220,427
其中:
1、新增A股开户数(户)
116,540
103,561
220,101
2、新增B股开户数(户)
171
155
326
三、期末股票账户数(万户)
8,364.85
0.00
8,269.22
16,634.07
其中:
1、期末A股账户数(万户)
8,212.05
8,169.70
16,381.75
(1)期末持仓A股账户数(万户)
3,196.63
2,502.79
5,699.42
(2)本周参与交易的A股账户数(万户)
616.56
578.89
1,195.45
2、期末B股账户数(万户)
152.80
99.52
252.32
四、期末休眠账户数(万户)
1,615.91
1,428.05
3,043.96
注:  ①期末有效账户数=期末A股账户数+期末B股账户数-期末休眠账户数;②新增股票账户数指当周新开出的股
票账户数;③期末股票账户数=期末A股账户数+期末B股账户数;  ④期末持仓A股账户指期末持有证券余额不为零
的A股账户;  ⑤本周参与交易A股账户指本周参与证券市场二级市场集中交易的A股账户。  ⑥休眠账户指根据中
国证监会《关于做好证券公司客户交易结算资金第三方存管有关账户规范工作的通知》以及本公司《关于进一步
规范账户管理工作的通知》的规定,经证券公司核实、申报的休眠账户数。  ⑦本周5个交易日。
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
air320322 + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

藤椅
shewenhao 发表于 2012-3-5 20:06:58
money is too low, if you reward 100, I could do that, lol

板凳
air320322 发表于 2012-3-6 00:07:21
相应楼上的要求,调整到200金币
不明真相的群众

报纸
Isscaliu 发表于 2012-3-6 03:18:38
try proc download
It was the best of times, it was the worst of times.

地板
air320322 发表于 2012-3-6 10:29:04
楼上的能具体说说嘛
不明真相的群众

7
爱萌 发表于 2012-3-6 12:57:10
这个其实不难,如果你用windows可能有点难道,但是用linux很简单的
最恨对我说谎或欺骗我的人

8
air320322 发表于 2012-3-6 15:05:26
可是我需要用windows下的SAS实现啊
不明真相的群众

9
tattoo27 发表于 2012-3-6 16:32:24
data work.links_to_crawl;
   length url $256;
   input url $;
   datalines;

www.chinaclear.cn/main/03/0303/030305/1330417819770.htm
;
run;


%macro crawler();
   %let html_num = 1;

   data work.links_crawled;
      length url $256;
   run;

%next_crawl:
   /* pop the next url off */
   %let next_url = ;

   data work.links_to_crawl;
      set work.links_to_crawl;
      if _n_ eq 1 then call symput("next_url", url);
      else output;
   run;

   %let next_url = %trim(%left(&next_url));

   %if "&next_url" ne "" %then %do;

      %put crawling &next_url ... ;

      /* crawl the url */
      filename _nexturl url "&next_url";

      /* put the file we crawled here */
      filename htmlfile "file%trim(&html_num).html";

      /* find more urls */
      data work._urls(keep=url);
         length url $256 ;
         file htmlfile;
         infile _nexturl length=len;
         input text $varying2000. len;

         put text;

         start = 1;
         stop = length(text);

         if _n_ = 1 then do;
            retain patternID;
            pattern = '/href="([^"]+)"/i';
            patternID = prxparse(pattern);
         end;

         /* Use PRXNEXT to find the first instance of the pattern, */
         /* then use DO WHILE to find all further instances.       */
         /* PRXNEXT changes the start parameter so that searching  */
         /* begins again after the last match.                     */
         call prxnext(patternID, start, stop, text, position, length);
         do while (position ^= 0);
            url = substr(text, position+6, length-7);
            * put url=;
            output;
            call prxnext(patternID, start, stop, text, position, length);
         end;
      run;

      /* add the current link to the list of urls we have already crawled */
      data work._old_link;
         url = "&next_url";
      run;
      proc append base=work.links_crawled data=work._old_link;
      run;

      /* only add urls that we haven't already crawled or that aren't queued up to be crawled */
      proc sql noprint;
         create table work._append as
            select url
            from work._urls
            where url not in (select url from work.links_crawled)
                  and url not in (select url from work.links_to_crawl);
      quit;

      /* only add urls that are absolute (http://...) */
      data work._append;
         set work._append;
         absolute_url = substrn(url, 1, 7);
         put absolute_url=;
         if absolute_url eq "http://" ;
         drop absolute_url;
      run;

      /* add new links */
      proc append base=work.links_to_crawl data=work._append force;
      run;

      /* increment our file number */
      %let html_num = %eval(&html_num + 1);

      /* loop */
      %goto next_crawl;
   %end;

%mend crawler;

%crawler();

/*定时自动靠你们啦~不负责任的飘过*/
已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Tato酱 + 1 + 1 + 1 观点有启发
webgu + 60 + 20 + 1 + 1 + 1 观点有启发

总评分: 经验 + 60  论坛币 + 20  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

10
air320322 发表于 2012-3-6 19:45:32
to:tattoo27
我运行之后,数据都为空
不明真相的群众

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 05:52