2010-07-31 1 views
0

안녕하세요, 저는이 사이트 (http://grecni.com/texttwist.php)에서 단어/결과를 보완 할 스크립트를 만들고 있습니다. 따라서 이미 http 요청 게시물을 준비하고 있습니다. 내가 지금 필요regex/ruby ​​도움말

만 가지 단어를 가져올 것입니다, 그래서 내가 그렇게처럼 보이는 HTML 소스와 함께 일하고 있어요 : 나는 단어 "SAE"와 같은 가져 오기 위해 노력하고

<html> 
<head> 
<title>Text Twist Unscrambler</title> 
<META NAME="keywords" CONTENT="Text,Twist,Text Twist,Unscramble,Free,Source,php"> 
</head> 
<body> 

<font face="arial,helvetica" size="3"> 
<p> 
<b>3 letter words</b><br>sae &nbsp; sac &nbsp; ess &nbsp; aas &nbsp; ass &nbsp; sea &nbsp; ace &nbsp; sec &nbsp; <p> 

<b>4 letter words</b><br>cess &nbsp; secs &nbsp; seas &nbsp; ceca &nbsp; sacs &nbsp; case &nbsp; asea &nbsp; casa &nbsp; aces &nbsp; caca &nbsp; <p> 

<b>5 letter words</b><br>cacas &nbsp; casas &nbsp; caeca &nbsp; cases &nbsp; <p> 
<b>6 letter words</b><br>access &nbsp; <br><br> 
Found 23 words in 0.22962 seconds 


<form action="texttwist.php" method="post"> 

enter scrambled letters and I'll return all word combinations<br> 
<input type="text" name="l" value="asceacas" size="20" maxlength="20"> 

<input type="submit" name="button" value="unscramble"> 
<input type="button" name="clear" value="clear" onClick="this.form.l.value='';"> 
</form><p> 

<a href=texttwist.phps>php source</a> 
- it's kinda ugly, but it's fast<p> 

<a href=/>back to my page</a> 

</body> 

</html> 

, "sav", "secs", "seas", "casas"등이 있습니다.

어떤 도움이 필요합니까?

내가 여기에서 무엇을 : link text

어떤 제안을 모르는 왔 먼? 도움?

+1

이 질문을 살펴보아야합니다. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 –

답변

0

애드리안에 의해 언급 된 것처럼 파서를 원하는 모든 종류의 견고성을 원하면 Nokogiri이 가장 많이 사용되는 솔루션입니다.

당신이 주장하는 경우, 페이지가 더 복잡대로 다음은 도움이 될 수 있습니다에 대한에있을 수 있습니다 madness의 인식 :

/^<b>\d+ letter words/ 

에 일치하는 라인을 검색하고 다음을 수행 할 수 있습니다 다음과 같이 비트를 찾아야합니다.

a = line.split(/<br>/)[1] # the second half 
a.gsub!('<p>', '') # take out the trailing <p> 
res = a.split(' &nbsp; ')# this is your data 

이것은 프로덕션 코드에서 원하는 것은 아닙니다. 파서를 배우는 것이 어떻게이 문제를 보는지를 어떻게 바꿀지는 놀랄 것입니다.

1

Nokogiri과 같은 HTML 구문 분석기를 사용하십시오.