2013-11-22 3 views
0

Новое на форуме. Мне интересно, знает ли кто, как Curl обрабатывает динамическую страницу с помощью SAS. Например, я попытался использовать аналогичный код ниже для завивки следующей динамической страницы в Base SAS: https://mysite.com/kl/livelink.exe?func=ll&objId=123, и результат показывает, что objId не распознается как внутренняя или внешняя команда, операционная программа или командный файл. программный или командный файл. У кого-нибудь есть идеи? Заранее спасибо.sas curl login для защищенного динамического сайта

%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 не признанный раздражает, но это не проблема. Это просто говорит, что & OBJID в URL-адресе не разрешается. Это нормально, вы хотите & OBJID.

Я подозреваю, что ваша проблема в знаке ^. Я подозреваю, что вам понадобится ., чтобы определить макрокоманду &a.

Вы действительно хотите, чтобы url.com был mysite.com/kl/livelink.exe?func=ll^& objId = 1117016710? (Добавлены пробелы, чтобы помочь ему выделиться)

+0

Hi DomPazz, Спасибо за вашу обратную связь. Я пробовал ссылку без^до:% nrstr (https://mysite.com/kl/livelink.exe?func=) & a.% Nrstr (& objId =) &b "); , и он все еще дает мне 0 записей и то же предупреждение об объекте. Он работает только так для динамической страницы. – 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