2010-07-31 104 views
0

嘿家伙们,所以我正在制作一个脚本来捕捉这个网站上的单词/结果(http://grecni.com/texttwist.php),所以我已经准备好了http请求,等等。帮助正则表达式/红宝石

我唯一现在需要的是获取出来的话,所以我用一个看起来像这样的HTML源代码的工作:

<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> 

我试图获取诸如“SAE” “sav”,“secs”,“seas”,“casas”等。

任何帮助?

这是最远的我已经得到了,不知道是什么,从这里做:link text

有什么建议?帮帮我?

+1

你需要看看这个问题:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2010-07-31 23:42:41

回答

0

如果你想要任何一种健壮性,你真的想要一个解析器,如Adrian所说,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 

这就是说,这不是你想要的任何生产代码。如果学习解析器会改变你看到这个问题的方式,你会感到惊讶。