2013-06-29 2 views
0

wp8의 webbrowser 컨트롤에로드 된 웹 사이트에서 일부 변수를 읽으 려합니다. HTML 스크립트로는 안전하지 않습니다. 그래서 "webBrowser.InvokeScript"또는 다른 것이 가능한지 잘 모르겠습니다. 이 같은WindowsPhone에서 HTML "windows. *"값 읽기

사이트의 모양을

<html class="no-js mobile"> 
<head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script> 
<title>test</title><meta content="width=320, initial-scale=1.0, user-scalable=no" name="viewport"> 

<script> 
    //<![CDATA[ 
    window.current_ip = '31.17.30.54'; 
    //]]> 
</script> 

<script> 
    //<![CDATA[ 
    window.current_checkout = "{&quot;id&quot;:0,&quot;domestic&quot;:false,&quot;amount&quot;:0.0,&quot;updated_at&quot;:0,&quot;created_at&quot;:0}"; 
    //]]> 
</script> 

<script type="text/javascript"> 
    var _sift = _sift || []; 
    _sift.push(['_setAccount', '637102']); 
    _sift.push(['_setUserId', '1878617619']); 
    _sift.push(['_trackPageview']); 

    (function() { 
    function loadSift() { 
     var sift = document.createElement('script'); 
     sift.type = 'text/javascript'; 
     sift.async = true; 
     sift.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'dtlilztwypawv.cloudfront.net/s.js'; 
     var s = document.getElementsByTagName('script')[0]; 
     s.parentNode.insertBefore(sift, s); 
    } 
    if (window.attachEvent) { 
     window.attachEvent('onload', loadSift); 
    } else { 
     window.addEventListener('load', loadSift, false); 
    } 
    })(); 
</script> 

</head> 

은 내가 할 수있는 누군가가 나를 HALP하면 정말 행복 할 것이다!

편집 -------------------

난 내가 한 걸음 더 가까이 솔루션을 것 같아요. 나는 성공이 코드를 실행 :

webBrowser.InvokeScript("eval", "newfunc_getmyvalue = function() { return 'hello'; }"); 
string s1 = (string)webBrowser.InvokeScript("newfunc_getmyvalue"); 

나는 이제 "window.current_checkout = ..."정확히 무엇을 알 필요가? 정말 변수를 설정하고 있습니까? 그리고이 값을 반환하는 'hello'스크립트를 수정하려면 어떻게해야합니까?

답변

0

호출 된 스크립트에서 반환 값을 반환하려면 windows.external.notify()를 호출해야하며 WebBrowser 컨트롤은 e.Value의 데이터를 catch하기 위해 ScriptNotify 이벤트 처리기를 선언해야합니다.

그래서이 :

webBrowser.InvokeScript("eval", "window.external.notify(window.current_checkout);"); 

웹 페이지에서 값을 방출해야하고,

private void webBrowser_ScriptNotify(object sender, NotifyEventArgs e) 
{ 
    string response = e.Value; 
    // do something wonderful with response 
} 

앱에서이를 포착한다.

0

HtmlAgilityPack 라이브러리를 사용하여 html을 구문 분석 한 다음 xpath 또는 linq-to-xml을 사용하여 변수를 찾을 수 있습니다. webclient으로 html을 다운로드 한 다음 라이브러리로 구문 분석하십시오. html을 다운로드하는 다른 방법들도 있습니다.

+0

WebClient가 일부 이벤트를 호출하는 것을 지원할 수도 있습니다. –

+0

안녕하세요, 응답을 위해 감사합니다! 다음과 같이 시도해보십시오. webBrowser.InvokeScript ("eval", "return window.current_project"); 그러나 "return"명령이 실패합니다. 예 : InvokeScript ("eval", "history.go()"); 이 작동합니다. 그래서 값을 반환하는 올바른 명령을 찾아야한다고 생각합니다. – Gordon2001