楼主: swu350407
19862 12

[问答] 求助:哪位大大会用SAS下载网页查询数据 [推广有奖]

  • 1关注
  • 1粉丝

大专生

36%

还不是VIP/贵宾

-

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

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
想从网上下载历史水位数据,比如
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 查询 下载 网页

沙发
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/ ...
谢谢,可以下载。但是论坛还是打不开

使用道具

7
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不支持?

使用道具

8
邓贵大 发表于 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.

使用道具

9
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 ...
非常感谢您的指点。

使用道具

10
邓贵大 发表于 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.

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

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

GMT+8, 2024-4-26 17:01