2010-05-17 2 views
0
<th>Prêmio</th> 
    <td colspan="11"> 
    <div class="res"><img class="r1" src="img/x.gif" alt="Madeira" title="Madeira" />215 | <img class="r2" src="img/x.gif" alt="Barro" title="Barro" />193 | <img class="r3" src="img/x.gif" alt="Ferro" title="Ferro" />192 | <img class="r4" src="img/x.gif" alt="Cereal" title="Cereal" />202</div><div class="carry"><img class="car" src="img/x.gif" alt="carregamento" title="carregamento" />802/1800</div></td></tr></tbody></table><table cellpadding="1" cellspacing="1" class="defender"> 
    <thead> 
    <tr> 

나는 "802/1800"을 얻으려고하고 있지만, 그것은 나를 미치게 만듭니다. 내가 사용하는 경우 : 그것은자바 스크립트 REGEX

을 작동하지만입니다 다음 단계로가는

var myregexp = /title="carregamento"/; 

: 이미 내가 널 returs

var myregexp = /title="carregamento" \/>/ 

.

var myregexp = /title="carregamento" \/>/; 

var match = myregexp.exec(document.documentElement.innerHTML); 

FM_log(7,"match="+match); 

if (match != null) 
    resultado.push(match[1]); 
+0

그것은 나를 위해 일한다. 당신은 YQL이나 'CDATA' 태그 같은 것을하고 있습니까? 표현은 [RegexPal] (http://regexpal.com) – sirhc

+0

에서도 작동합니다. 아니요, 아닙니다. 아직도 여기서 일하지 않습니다. – FernandoSBS

답변

1

정확한 코드를 게시해야합니다. 정확하게 정규 표현식 개체와 관련이없는 것으로 약간 잘못 될 수 있기 때문입니다.

regextester.com에서 테스트하면 완벽하게 작동합니다.

다음 정규식을 사용하면 최대 802/1800까지의 문자열과 일치하고 캡처 그룹으로 802/1800을 선택합니다.

title="carregamento" \/>(\d+\/\d+) 
+0

아래 코드와 관련된 부분이 있습니다. – FernandoSBS

+0

regextester.com이 작동하지만 올바른 sintax 인 을 입력하지 않은 경우 /title = "carregamento"\ /> (\ d + \/\ d +)/ – FernandoSBS

+0

문자열을 나타내는 "/"문자는 정규식입니다. 자바 스크립트가 필요하지 않습니다. 첫 번째 시도하지 않으면 실제 정규식 문자열 – Rich

1

당신이 게시 한 정규 표현식은 올바른 :

var에 myregexp =/제목 = "carregamento"/>/

실제로 하나가 바로 은 "1,800분의 802" 전에 문자열과 일치 문자열

+0

전체 코드가 작동하지 않습니다. 나를 null로 돌려주고있다. – FernandoSBS

0

문제가 무엇인지 발견했습니다. 분명히 파이어 폭스가 내가 "문서 소스보기"를 선택할 때와 자바 스크립트가 소스로서 제공하는 것을 보여주는 것과 다른 점이있다.

파이어 폭스 소스 :

<img class="car" src="img/x.gif" alt="carregamento" title="carregamento" />802/1800</div> 

자바 스크립트 소스 : (나는 나에게 document.documentElement.innerHTML

<img class="car" src="img/x.gif" alt="carregamento" title="carregamento">802/1800</div> 

그렇게 차이가 단순한 />

되었다 보여주는 LOG를 만들어 여기의 차이입니다

코드도 개선되었습니다.

 var myregexp = /title="carregamento">(.+?)\/(.+?)<\/div>/; 


     FM_log(7,"myregexp="+myregexp); 

     var resultado = []; 

     var match = myregexp.exec(document.documentElement.innerHTML); 

     //FM_log(7, document.documentElement.innerHTML); 

     FM_log(7,"match="+match); 

     if (match != null) { 
      resultado.push(match[1]) 
      resultado.push(match[2]) 
      }; 

     FM_log(7,"resultado[0]="+resultado[0]+" resultado[1]="+resultado[1]);   

     efficiency = Math.round(resultado[0]/resultado[1] * 100); 

     gain = resultado[0]; 

이것은 최종 코드이며 완벽하게 작동합니다.

기여한 모든 분들께 감사드립니다.