前段时间眼红好友们的人人帐号级别都很高, 我就写了一个模拟登录的脚本, 每天定时登录人人并发布一个新的状态, 加快升级. 在考虑状态用语的时候, 突然想到了电驴子 VeryCD 的标题每次都不一样, 而且很多语句都非常励志, 或者积极向上. 于是考虑把它爬下来, 随机选择一个, 作为人人网状态发布. 现在我把读取 VeryCD 网站标题的代码张贴一下.
PHP 方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * 取得当日 VeryCD 的随机标题 * * @return array */ function getTitlesOfVeryCD() { $orgContent = file_get_contents('http://www.verycd.com/statics/title.saying'); $matchResult = preg_match('/new\s+Array\((.+)\);\s+_VC_/', $orgContent, $matches); $results = array(); if ($matchResult) { $results = explode('\', ', $matches[1]); foreach ($results as &$v) { $v = str_replace('\'', '', $v); } } unset($orgContent, $matches); return $results; } |
Java 方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * 读取 VeryCD 的随机标题 * * @author yinheli * */ public class TitlesOfVeryCD { /** * 取得当日全部的标题 * * @return 当天的标题数组 * @throws IOException */ public static String[] get() throws IOException { URL url = new URL("http://www.verycd.com/statics/title.saying"); BufferedReader br = new BufferedReader( new InputStreamReader( url.openConnection().getInputStream() ) ); StringBuilder contentSB = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { contentSB.append(line); } br.close(); String content = contentSB.toString(); Pattern p = Pattern.compile("new\\s+Array\\((.+)\\);\\s+_VC_"); Matcher m = p.matcher(content); String[] results = null; if (m.find()) { results = m.group(1).split("',\\s?"); for (int i = 0; i < results.length; i++) { results[i] = results[i].replace("'", ""); } } return results; } } |
声明:本站遵循署名-非商业性使用-相同方式共享3.0共享协议. 转载请注明转自 PhilNa ™
你这个主题 怎么实现
回复评论者评论邮件发送啊??
附上我的QQ:287450217
不过 最好 到gmail邮箱吧
谢谢
你这款主题不错,我很喜欢。。
就是 前面问题 咋解决的?
求助……
多谢!