use java style regular expression in groovy fetch and extractor info ,fucking urgly
2012-06-28 15:46
411 查看
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
System.properties.putAll( ["http.proxyHost":"10.10.224.97", "http.proxyPort":"80","http.proxyUserName":"admin", "http.proxyPassword":"admin888"] )
def url="http://detail.tmall.com/item.htm?id=8039043384&"
url="http://www.baidu.com"
html=url.toURL().text
//def matcher=( html=~ /<strong id="J_StrPrice"/ )
//println matcher
println html
String ResultString = null;
try {
Pattern regex = Pattern.compile("<strong id=\"J_StrPrice\" >([\\s\\S]*?)</strong>");
Matcher regexMatcher = regex.matcher(html);
if (regexMatcher.find()) {
ResultString = regexMatcher.group(1);
println(ResultString)
}
else
{
println("zzzz")
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
System.properties.putAll( ["http.proxyHost":"10.10.224.97", "http.proxyPort":"80","http.proxyUserName":"admin", "http.proxyPassword":"admin888"] )
def url="http://detail.tmall.com/item.htm?id=8039043384&"
url="http://www.baidu.com"
html=url.toURL().text
//def matcher=( html=~ /<strong id="J_StrPrice"/ )
//println matcher
println html
String ResultString = null;
try {
Pattern regex = Pattern.compile("<strong id=\"J_StrPrice\" >([\\s\\S]*?)</strong>");
Matcher regexMatcher = regex.matcher(html);
if (regexMatcher.find()) {
ResultString = regexMatcher.group(1);
println(ResultString)
}
else
{
println("zzzz")
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
相关文章推荐
- MyEclipse 强制杀掉后 INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind
- LeetCode – Regular Expression Matching in Java
- How to use Regular Expression in LotusScript
- Use regular expression in notepad++
- Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?an
- how to save a c++ object in java object and use it
- UseRegularExpression.java
- The most simple and easy to use Qt GUI library plug-in FTStyle (1)
- The most simple and easy to use Qt GUI library plug-in FTStyle (2)The latest version - 2017.10
- When to use comparable and comparator interfaces in java
- Regular Expression in C# - How to make use of Expresso
- Java and Regular Expression
- Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?an
- Regular Expression Pocket Reference: Regular Expressions for Perl, Ruby, PHP, Python, C, Java and .N
- Use an eclipse plugin project as jar library in a regular java project
- Why and when to use AtomicIntegerFieldUpdater in java?
- Get number from string with regular expression in java
- use regular expression in the oracle sqlplus
- Regular Expression Matching in Java
- Difference between RegularEnumSet and JumboEnumSet in Java