楼主: rainfall2003
3171 9

[原创博文] 请教sas如何提取html网页中的内容 [推广有奖]

  • 0关注
  • 0粉丝

本科生

26%

还不是VIP/贵宾

-

威望
0
论坛币
65 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1196 点
帖子
73
精华
0
在线时间
90 小时
注册时间
2007-5-28
最后登录
2014-5-5

楼主
rainfall2003 发表于 2012-4-18 10:23:43 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
已经下载了网页的内容,为html document格式,我现在需要提取里面的内容,例如:查找「标题:」后紧接着的内容,该如何实现。请大家帮帮忙,谢谢啦!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:HTML 如何提取 htm Document DOCUME document 如何 网页

沙发
chendonghui1987 发表于 2012-4-18 15:19:29
看你想怎么做了,我有一个提取乐和彩的双色球数据的程序

藤椅
rainfall2003 发表于 2012-4-18 16:31:24 来自手机
chendonghui1987 发表于 2012-4-18 15:19
看你想怎么做了,我有一个提取乐和彩的双色球数据的程序
sas的程序吗?

板凳
chendonghui1987 发表于 2012-4-19 15:15:19
对呀sas的程序,把双色球从2003年到现在出现的中奖纪录都提取了,大概1300多条数据

报纸
chendonghui1987 发表于 2012-4-19 15:15:53
对呀,提起了2003年到现在的大概一千多条数据吧

地板
rainfall2003 发表于 2012-4-24 14:24:46
chendonghui1987 发表于 2012-4-19 15:15
对呀sas的程序,把双色球从2003年到现在出现的中奖纪录都提取了,大概1300多条数据
能否发来学习下

7
chendonghui1987 发表于 2012-4-24 14:48:59
可以,希望对你有所帮助.我提取的双色球.



%macro lehecai(sumpage,start,end);

        %let page = %nrstr(&page);
        %let ds = %nrstr(&ds);
        %let de = %nrstr(&de);

        proc sql noprint;
                create table cdh.lehe1(
                        dt date label="开奖日期" format=yymmdd10.,
                        issue varchar(10) label="期号",
                        c1 numeric,
                        c2 numeric,
                        c3 numeric,
                        c4 numeric,
                        c5 numeric,
                        c6 numeric,
                        c7 numeric,
                        sell numeric label="销量"
                );
               
                create table cdh.lehe2(
                        dt date label="开奖日期" format=yymmdd10.,
                        issue varchar(10) label="期号",
                        number varchar(14) label="中奖号码",
                        sell numeric label="销量"
                );
        quit;

        %do i = 1 %to &sumpage ;
                %let lehe_url = http://baidu.lehecai.com/lottery ... rt&de=&end;
                %put &lehe_url;

                filename lehecai url "http://baidu.lehecai.com/lottery/draw/list/50?lottery_type=50&page=&i&ds=&start&de=&end" RECFM=v;

                /*读入此网页所有内容到变长字段content中*/
                data work.a;
                    infile lehecai length=len;
                    length content $32766. ;
                    input content $varying32766. len;
                run;
                 
                data work.b;       
                        length content_final $20.;
                        set work.a;
                        retain flag;
                        flag + 1;

                        /*取出包含Shibor 期限字符的观测及其下一个观测(即期限所对应的Shibor利率)*/                  ;
                        if  index(content,'<td class="td1">')>0
                                        or  index(content,'<a href="/lottery/draw/view/50?phase=')>0
                                        or  index(content,'<span class="ball_1">')>0
                                        or  index(content,'<span class="ball_2">')>0
                                        or  index(content,'<td class="td4">')>0 then do;
                                flag = 1;
                        end;
                        else do;
                                flag = 0;
                        end;

                        /*去除所有被<>包含的代码及其所有空格*/
                        pattern2 = 's/<.+?>//s';
                        retain pattern_id;
                        pattern_id = prxparse(pattern2);
                        call prxchange(pattern_id, -1, content);
                        content_new = compress(content,"0123456789-");
                        content_final = compress(content,content_new);
                       
                        if flag = 1 then do;
                                i + 1;
                                retain i;
                        end;
                        else do;
                                delete;
                        end;
                       
                        if i in (1,2) then delete;
                        keep content_final;
                run;

                data work.c;
                        set work.b;
                        if mod(_n_,10) = 1 then do;
                                id = 1;
                                retain id;
                        end;
                        else do;
                                id+1;
                                retain id;
                        end;
                run;

                proc sort data=work.c;
                        by id;
                quit;

                proc transpose data=work.c out=work.d(drop = id _name_) ;
                        var content_final;
                        by id;
                run;
               

                proc transpose data=work.d out=work.e(drop = _name_);
                        var _all_;
                run;

                data work.f(drop = col1-col10);
                        length dt 8. issue $10. c1-c7 8. sell 8.;
                        set work.e;
                        dt = input(col1,yymmdd10.);
                        format dt yymmdd10.;
                        issue = col2;
                        c1 = input(col3,8.);
                        c2 = input(col4,8.);
                        c3 = input(col5,8.);
                        c4 = input(col6,8.);
                        c5 = input(col7,8.);
                        c6 = input(col8,8.);
                        c7 = input(col9,8.);
                        sell = input(col10,comma18.);

                run;

                data work.g(keep = dt issue number sell);
                        length dt 8. issue $10. number $14. sell 8.;
                        set work.e;
                        dt = input(col1,yymmdd10.);
                        format dt yymmdd10.;
                        issue = col2;
                        number = compress(col3)||compress(col4)||compress(col5)||compress(col6)||compress(col7)||compress(col8)||compress(col9);
                        sell = input(col10,comma18.);
                run;

                proc sql noprint;
                        insert into cdh.lehe1
                                select dt,
                                        issue,
                                        c1,
                                        c2,
                                        c3,
                                        c4,
                                        c5,
                                        c6,
                                        c7,
                                        sell
                                from work.f;

                        insert into cdh.lehe2
                                select dt,
                                        issue,
                                        number,
                                        sell
                                from work.g;
                quit;
        %end;

%mend;

%lehecai(45,2001-01-01,2012-12-31);

8
chendonghui1987 发表于 2012-4-24 14:49:31
可以呀,希望对你有所帮助.

%macro lehecai(sumpage,start,end);

        %let page = %nrstr(&page);
        %let ds = %nrstr(&ds);
        %let de = %nrstr(&de);

        proc sql noprint;
                create table cdh.lehe1(
                        dt date label="开奖日期" format=yymmdd10.,
                        issue varchar(10) label="期号",
                        c1 numeric,
                        c2 numeric,
                        c3 numeric,
                        c4 numeric,
                        c5 numeric,
                        c6 numeric,
                        c7 numeric,
                        sell numeric label="销量"
                );
               
                create table cdh.lehe2(
                        dt date label="开奖日期" format=yymmdd10.,
                        issue varchar(10) label="期号",
                        number varchar(14) label="中奖号码",
                        sell numeric label="销量"
                );
        quit;

        %do i = 1 %to &sumpage ;
                %let lehe_url = http://baidu.lehecai.com/lottery ... rt&de=&end;
                %put &lehe_url;

                filename lehecai url "http://baidu.lehecai.com/lottery/draw/list/50?lottery_type=50&page=&i&ds=&start&de=&end" RECFM=v;

                /*读入此网页所有内容到变长字段content中*/
                data work.a;
                    infile lehecai length=len;
                    length content $32766. ;
                    input content $varying32766. len;
                run;
                 
                data work.b;       
                        length content_final $20.;
                        set work.a;
                        retain flag;
                        flag + 1;

                        /*取出包含Shibor 期限字符的观测及其下一个观测(即期限所对应的Shibor利率)*/                  ;
                        if  index(content,'<td class="td1">')>0
                                        or  index(content,'<a href="/lottery/draw/view/50?phase=')>0
                                        or  index(content,'<span class="ball_1">')>0
                                        or  index(content,'<span class="ball_2">')>0
                                        or  index(content,'<td class="td4">')>0 then do;
                                flag = 1;
                        end;
                        else do;
                                flag = 0;
                        end;

                        /*去除所有被<>包含的代码及其所有空格*/
                        pattern2 = 's/<.+?>//s';
                        retain pattern_id;
                        pattern_id = prxparse(pattern2);
                        call prxchange(pattern_id, -1, content);
                        content_new = compress(content,"0123456789-");
                        content_final = compress(content,content_new);
                       
                        if flag = 1 then do;
                                i + 1;
                                retain i;
                        end;
                        else do;
                                delete;
                        end;
                       
                        if i in (1,2) then delete;
                        keep content_final;
                run;

                data work.c;
                        set work.b;
                        if mod(_n_,10) = 1 then do;
                                id = 1;
                                retain id;
                        end;
                        else do;
                                id+1;
                                retain id;
                        end;
                run;

                proc sort data=work.c;
                        by id;
                quit;

                proc transpose data=work.c out=work.d(drop = id _name_) ;
                        var content_final;
                        by id;
                run;
               

                proc transpose data=work.d out=work.e(drop = _name_);
                        var _all_;
                run;

                data work.f(drop = col1-col10);
                        length dt 8. issue $10. c1-c7 8. sell 8.;
                        set work.e;
                        dt = input(col1,yymmdd10.);
                        format dt yymmdd10.;
                        issue = col2;
                        c1 = input(col3,8.);
                        c2 = input(col4,8.);
                        c3 = input(col5,8.);
                        c4 = input(col6,8.);
                        c5 = input(col7,8.);
                        c6 = input(col8,8.);
                        c7 = input(col9,8.);
                        sell = input(col10,comma18.);

                run;

                data work.g(keep = dt issue number sell);
                        length dt 8. issue $10. number $14. sell 8.;
                        set work.e;
                        dt = input(col1,yymmdd10.);
                        format dt yymmdd10.;
                        issue = col2;
                        number = compress(col3)||compress(col4)||compress(col5)||compress(col6)||compress(col7)||compress(col8)||compress(col9);
                        sell = input(col10,comma18.);
                run;

                proc sql noprint;
                        insert into cdh.lehe1
                                select dt,
                                        issue,
                                        c1,
                                        c2,
                                        c3,
                                        c4,
                                        c5,
                                        c6,
                                        c7,
                                        sell
                                from work.f;

                        insert into cdh.lehe2
                                select dt,
                                        issue,
                                        number,
                                        sell
                                from work.g;
                quit;
        %end;

%mend;

%lehecai(45,2001-01-01,2012-12-31);

9
chendonghui1987 发表于 2012-4-24 14:51:10
我的代码怎么不能输入了,

1.bmp (179.15 KB)

1.bmp

10
chendonghui1987 发表于 2012-4-24 14:52:05
你把邮箱给我,我发邮件给你吧

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-2 17:24