2013-11-22 21 views
0

論壇新手。我想知道如果有人知道Curl如何使用SAS處理動態頁面。例如,我嘗試使用下面類似的代碼來捲曲Base SAS中的以下動態頁面:https://mysite.com/kl/livelink.exe?func=ll&objId=123,結果顯示'objId'不被識別爲內部或外部命令,可操作程序或批處理文件。程序或批處理文件。任何人有任何想法?提前致謝。sas curl登錄到安全的動態網站

%let a = ll; 
%let b = 1117016710; 
data _null_; 
    call symput ('curl_cmd', "&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a^%nrstr(&objId=)&b "); 
run; 

filename curl pipe "&curl_cmd" lrecl=32767; 
data tmp; 
    length xml $&maxchars; 
    infile curl truncover end=eof; 
    input @1 xml $&maxchars..; 
    if lengthn(xml) ge &maxchars then do;  
    put "ERROR: FAILED FOR process BECAUSE XML WAS > &maxchars CHARS"; 
    put "OBSERVATION: " _n_; 
    put xml; 
    stop; 
    end; 
run; 
filename curl clear; 

the results shows: 
filename curl pipe "&curl_cmd" lrecl=32767; 
WARNING: Apparent symbolic reference OBJID not resolved. 

PROCESS=C:\test\curl\curl.exe -k -u user:pwd 
     https://mysite.com/kl/livelink.exe?func=ll^&objId=1117016710, 
     RECFM=V,LRECL=32767 

Stderr output: 
    Total  Received Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 

    0  0 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0 
    0  0 0 
    0 0  0  0  0 --:--:-- --:--:-- --:--:--  0 
NOTE: 0 records were read from the infile CURL. 
NOTE: The data set WORK.TMP has 0 observations and 1 variables. 
NOTE: DATA statement used (Total process time): 
     real time   0.35 seconds 

喬的建議後,我做了一些改動,這裏是下面的結果:

%let curl_executable = C:\test\curl\curl.exe; 
%let maxchars  = 3000; 
%let userpass  = user:pwd; 

%let a = ll; 
%let b = 1117016710; 
%let curl_cmd=&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b ; 
%put &=curl_cmd; 

data _null_; 
    call symput ('curl_cmd', '&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b'); 
run; 
%put &=curl_cmd; 

filename curl pipe "&curl_cmd" lrecl=32767; 
data tmp; 
    length xml $&maxchars; 

    infile curl truncover end=eof; 
    input @1 xml $&maxchars..; 

    if lengthn(xml) ge &maxchars then do;  
    put "ERROR: FAILED FOR process BECAUSE XML WAS > &maxchars CHARS"; 
    put "OBSERVATION: " _n_; 
    put xml; 
    stop; 
    end; 
run; 
filename curl clear; 

結果日誌文件的回報:

37 %let curl_executable = C:\test\curl\curl.exe; 
38 %let maxchars  = 3000; 
39 %let userpass  = user:pwd; 
40 %let a = ll; 
41 %let b = 1117016710; 
42 %let curl_cmd=&curl_executable -k -u &userpass 
42 ! %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b 
42 ! ; 
43 %put &=curl_cmd; 
CURL_CMD=C:\test\curl\curl.exe -k -u user:pwd 
https://mysite.com/kl/livelink.exe?func=ll&objId=1117016710 
44 
45 data _null_; 
46  call symput ('curl_cmd', '&curl_executable -k -u &userpass 
46 ! %nrstr(https://mysite.com/kl/livelink.exe?func=)&a.%nrstr(&objId)=&b' 
46 !); 
47 run; 

NOTE: DATA statement used (Total process time): 
     real time   0.00 seconds 
     cpu time   0.00 seconds 


48 %put &=curl_cmd; 
CURL_CMD=C:\test\curl\curl.exe -k -u user:pwd 
https://mysite.com/kl/livelink.exe?func=ll&objId=1117016710 
49 
50 filename curl pipe "&curl_cmd" lrecl=32767; 
51 data tmp; 
52  length xml $&maxchars; 
53 
54  infile curl truncover end=eof; 
55  input @1 xml $&maxchars..; 
56 
57  if lengthn(xml) ge &maxchars then do; 
58  put "ERROR: FAILED FOR process BECAUSE XML WAS > &maxchars CHARS"; 
59  put "OBSERVATION: " _n_; 
60  put xml; 
61  stop; 
62  end; 
63 run; 

NOTE: The infile CURL is: 
     Unnamed Pipe Access Device, 

     PROCESS=C:\test\curl\curl.exe -k -u user:pwd 
     https://mysite.com/kl/livelink.exe?func=ll&objId=1117016710, 
     RECFM=V,LRECL=32767 

Stderr output: 
    Total  Received Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 

    0  0 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0 
    0  0 0 
    0 0  0  0  0 --:--:-- --:--:-- --:--:--  0 
'objId' is not recognized as an internal or external command, 
operable program or batch file. 
NOTE: 0 records were read from the infile CURL. 
NOTE: The data set WORK.TMP has 0 observations and 1 variables. 
NOTE: DATA statement used (Total process time): 
     real time   0.43 seconds 
     cpu time   0.04 seconds 


64 filename curl clear; 
NOTE: Fileref CURL has been deassigned. 
65 
66 
67 proc print data=tmp; 
68 run; 

NOTE: No observations in data set WORK.TMP. 
NOTE: PROCEDURE PRINT used (Total process time): 
     real time   0.00 seconds 
     cpu time   0.00 seconds 
+0

你需要做的第一件事是通過工藝試驗串組輸出。複製/粘貼從「=」到逗號前的所有內容。在命令行執行它。如果這樣做,那麼你有一些問題正確地得到命令處理器;如果這不起作用,請修復它,使其可以正常工作,然後更改SAS以使宏變量與該變量匹配。 – Joe

回答

0

對宏觀OBJID警告不承認是煩人的,但它不是問題。這只是說,在URL中的OBJID &沒有解決。沒關係,你想要& OBJID。

我懷疑你的問題是URL中的^字符。我懷疑你需要一個.來代替&a宏變量。

你真的想要的網址是mysite.com/kl/livelink.exe?func=ll^& objId = 1117016710? (由空格來幫助它脫穎而出)

+0

嗨DomPazz,感謝您的快速反饋。我試過鏈接沒有^之前:%nrstr(https://mysite.com/kl/livelink.exe?func=)&a。%nrstr(&objId =)&b "); 它仍然給我0記錄和關於objId相同的警告。它只對動態頁面有這樣的表現。 – jackdanel

+0

^會結束宏變量,所以這不是問題(除非^是一個意外)。也就是說,最初的問題表明它不合適,所以我很困惑爲什麼它在那裏。 – Joe

0

這可能有助於簡化錯誤檢查,如果它實際上並沒有解決你的問題:

用%讓利定義一個宏變量,不叫SYMPUT,除非你有做後者的一個很好的理由。在這種情況下,由於您使用宏變量作爲組件,您可能沒有很好的理由。

%let a = ll; 
%let b = 1117016710; 
%let curl_executable=c:\curl.exe; 
%let userpass=password; 

%let curl_cmd=&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a%nrstr(&objId=)&b ; 
%put &=curl_cmd; 

其次,爲了避免警告,如果你使用call symput,你可以把它放在單引號中。別擔心,&s在實際使用時仍然可以解決。

data _null_; 
    call symput ('curl_cmd', '&curl_executable -k -u &userpass %nrstr(https://mysite.com/kl/livelink.exe?func=)&a%nrstr(&objId=)&b'); 
run; 
%put &=curl_cmd; 

(旁註:& =僅適用於9.3+,所以如果你有9.2,刪除=)

+0

我編輯了我的帖子供您閱讀日誌文件。在此先感謝您的任何建議。 – jackdanel