请选择 进入手机版 | 继续访问电脑版
楼主: swu350407
18488 12

[问答] 求助:哪位大大会用SAS下载网页查询数据 [分享]

  • 1关注
  • 1粉丝

大专生

31%

还不是VIP/贵宾

-

威望
0
论坛币
472 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
710 点
帖子
25
精华
0
在线时间
64 小时
注册时间
2012-2-3
最后登录
2020-11-26

swu350407 发表于 2013-6-3 09:02:18 |显示全部楼层
想从网上下载历史水位数据,比如
http://www.ctgpc.com.cn/inc/sqsk.php
从网上找到类似代码:
源自本坛https://bbs.pinggu.org/thread-1118208-1-1.html

%let url = http://funds.money.hexun.com/fun ... 2.aspx?code=000001;
%let code = %scan(&url,2,'=');

filename raw url "&url";

data temp;
  infile raw length=len lrecl=5000;
  input x $varying5000.len;
run;

data temp2;
  set temp;
  retain code pattern_id ;
  if _n_ = 1 then do;
    code = &code;
        pattern_id = prxparse("#(\d{4}-\d{2}-\d{2}|\d\.\d{4})</td>$#");
  end;
  if prxmatch(pattern_id,strip(x));
  call prxposn(pattern_id,1,start,length);
  y = substrn(x,start,length);
  keep code y;
run;

data final;
  set temp2;
  retain date unit_value cum_value;
  format code Z6. date yymmdd10. unit_value cum_value 8.4;
  if mod(_n_,3) = 1 then date = input(y,yymmdd10.);
  else if mod(_n_,3) = 2 then unit_value = input(y,8.);
  else if mod(_n_,3) = 0 then do;
    cum_value = input(y,8.);
        output;
  end;
  drop y;
run;



非常感谢guoluo提供的代码,希望guoluo能继续解答。跪拜ing
关键词:PrxMatch filename Pattern RXPARSE varying 查询 下载 网页

stata SPSS
823954913 发表于 2013-6-3 11:02:16 |显示全部楼层
同求,用post得到网页的数据。
回复

使用道具 举报

邓贵大 发表于 2013-6-4 12:18:52 |显示全部楼层
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.
回复

使用道具 举报

swu350407 发表于 2013-6-11 23:58:29 |显示全部楼层
邓贵大 发表于 2013-6-4 12:18
http://support.sas.com/resources/papers/proceedings12/121-2012.pdf
https://groups.google.com/forum/ ...
谢谢。但是网页打不开?需要翻墙吗
回复

使用道具 举报

swu350407 发表于 2013-6-12 00:02:13 |显示全部楼层
swu350407 发表于 2013-6-11 23:58
谢谢。但是网页打不开?需要翻墙吗
谢谢。可以下载了
回复

使用道具 举报

swu350407 发表于 2013-6-12 00:03:07 |显示全部楼层
邓贵大 发表于 2013-6-4 12:18
http://support.sas.com/resources/papers/proceedings12/121-2012.pdf
https://groups.google.com/forum/ ...
谢谢,可以下载。但是论坛还是打不开
回复

使用道具 举报

swu350407 发表于 2013-6-12 00:17:51 |显示全部楼层
邓贵大 发表于 2013-6-4 12:18
http://support.sas.com/resources/papers/proceedings12/121-2012.pdf
https://groups.google.com/forum/ ...
用x “curl http://...."会出错?是不是9.3不支持?
回复

使用道具 举报

邓贵大 发表于 2013-6-12 02:01:27 |显示全部楼层
cURL is a 3rd party utility that needs to be installed.
http://curl.haxx.se/download.html
With cURL, it's just as easy as
  1. filename curl pipe 'curl -d NeedCompleteTime2=20111111 http://www.ctg.com.cn/inc/sqsk.php';

  2. data _null_;
  3.         infile curl;
  4.         input;
  5.         put _infile_;
  6. run;
复制代码
Substitute 20111111 with any date you may want.
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.
回复

使用道具 举报

swu350407 发表于 2013-6-12 22:12:58 |显示全部楼层
邓贵大 发表于 2013-6-12 02:01
cURL is a 3rd party utility that needs to be installed.
http://curl.haxx.se/download.html
With cUR ...
非常感谢您的指点。
回复

使用道具 举报

邓贵大 发表于 2013-6-12 22:37:31 |显示全部楼层
swu350407 发表于 2013-6-12 22:12
非常感谢您的指点。
Sorry I goofed. There's actually a PROC HTTP been added since SAS 9.2.
So you don't need cURL any more.
http://support.sas.com/documenta ... un1ru90xy4s36oa.htm
  1. filename in "in.txt";
  2. filename out "out.txt";
  3. data _null_;
  4.    file in;
  5.    input;
  6.    put _infile_;
  7. datalines4;
  8. NeedCompleteTime2=2011-11-11
  9. ;;;;

  10. proc http in=in out=out url="http://www.ctg.com.cn/inc/sqsk.php"
  11.      method="post" ct="application/x-www-form-urlencoded";
  12. run;
复制代码
If you don't have SAS 9.2+, here's a vanilla version
  1. filename REMOTE socket "www.ctg.com.cn:80" termstr=LF;
  2. data _null_;
  3.         infile REMOTE;
  4.         file REMOTE;
  5.         name_value_pairs = 'NeedCompleteTime2=2011-11-11';
  6.         len = length (name_value_pairs);
  7.         put
  8.                 "POST /inc/sqsk.php HTTP/1.1"
  9.                 / "Host: www.ctg.com.cn"
  10.                 / "Content-Length: " len
  11.                 / "Content-Type: application/x-www-form-urlencoded"
  12.                 // name_value_pairs
  13.                 /
  14.                 ;
  15.         file 'out.txt';
  16.         putlog / '---- RESPONSE ----' /;
  17.         do until(index(lowcase(_infile_), '</html>'));
  18.             input;
  19.             put _infile_;
  20.         end;
  21.         stop;
  22. run;
复制代码
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.
回复

使用道具 举报

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

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2021-1-20 12:02