| 15 | import java.util.regex.Pattern; |
| 16 | |
| 17 | public class WebCurl { |
| 18 | |
| 19 | /* |
| 20 | * 函数说明: |
| 21 | * getTitle(String webcontent): |
| 22 | * 输入参数:web页面信息html |
| 23 | * 返回结果:标题 |
| 24 | * */ |
| 25 | |
| 26 | public static String getTitle(String webContent){ |
| 27 | Pattern pattern = Pattern.compile("<title>.*?</title>",Pattern.CASE_INSENSITIVE|Pattern.DOTALL); |
| 28 | Matcher ma =pattern.matcher(webContent); |
| 29 | while (ma.find()){ |
| 30 | //System.out.println(ma.group()); |
| 31 | return outTag(ma.group()); |
| 32 | } |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | |
| 37 | //去除标题中的一些无关信息 |
| 38 | public static String outTag(String s) |
| 39 | { |
| 40 | String title = s.replaceAll("<.*?>", ""); |
| 41 | title=replaceBlank(title); |
| 42 | title = title.replace("首页", ""); |
| 43 | title = title.replace("-", ""); |
| 44 | title = title.replace("主页", ""); |
| 45 | title = title.replace("官网", ""); |
| 46 | title = title.replace("欢迎进入", ""); |
| 47 | title = title.replace("欢迎访问", ""); |
| 48 | title = title.replace("登录入口", ""); |
| 49 | return title; |
| 50 | } |
| 51 | |
| 52 | //除去标题字符串中的\t制表符 \n回车 \r换行符 |
| 53 | public static String replaceBlank(String str) { |
| 54 | String dest = ""; |
| 55 | if (str!=null) { |
| 56 | Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
| 57 | Matcher m = p.matcher(str); |
| 58 | dest = m.replaceAll(""); |
| 59 | } |
| 60 | return dest; |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * 功能说明: |
| 65 | * 输入参数:域名 |
| 66 | * 返回参数:IP地址 |
| 67 | * */ |
| 68 | public void getIpName(WebInfo wi,String damin){ |
| 69 | try{ |
| 70 | InetAddress inetAddress = InetAddress.getByName(damin); |
| 71 | String host_damin =inetAddress.getHostAddress(); |
| 72 | wi.domain = damin; |
| 73 | wi.ip = host_damin; |
| 74 | System.out.println(wi.ip); |
nothing calls this directly
no outgoing calls
no test coverage detected