我有以下工作代码(在这里和那里进行了更改,以便您在复制和粘贴时动动脑筋)。我想改进它,这样它就可以检测到所有无效的页面,包括出售的域名。它的工作效率约为89%。如果你看到任何东西,我可以通过使用其他现有的库或小调整来改进,这将是非常棒的。
List all = linkService.getAllLinks();
notValidLinks = new LinkedList();
final ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(39867);
int poolSize = 90;
int maxPoolSize = 100;
long keepAliveTime = 40;
ThreadPoolExecutor tpe = new ThreadPoolExecutor(poolSize, maxPoolSize,
keepAliveTime, TimeUnit.SECONDS, queue);
for (link : all) {
Thread task = new CheckSite(link);
tpe.execute(task);
System.out.println("Task count:" + queue.size());
}
class CheckSite extends Thread {
Link link;
CheckSite(Link link) {
this.link = link;
}
public void run() {
boolean notValid = false;
try {
log.info(link.getLink() + " " + link.getId());
URL u = new URL(link.getLink());
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
HttpURLConnection.setFollowRedirects(false);
huc.setConnectTimeout(40000);
huc.setRequestMethod("GET");
huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
huc.connect();
int code = huc.getResponseCode();
if (code != HttpURLConnection.HTTP_OK
&& code != HttpURLConnection.HTTP_MOVED_PERM
&& code != HttpURLConnection.HTTP_MOVED_TEMP ){
notValid = true;
log.info("Invalid code: " + code + " - " + link.getLink());
}
if (code == HttpURLConnection.HTTP_MOVED_PERM) {
log.info(link.getLink() + " Perm move");
}
if (code == HttpURLConnection.HTTP_MOVED_TEMP) {
log.info(link.getLink() + " Temp move");
}
try {
if (!notValid) {
BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
notValid = StringUtils.containsIgnoreCase(Jsoup.parse(stringBuilder.toString()).text(), "Related Searches");
}
} catch (Exception e) {
log.error(e.getMessage());
}
huc.disconnect();
} catch (MalformedURLException me) {
log.info("Malformed URL:" + link.getLink());
notValid = true;
} catch (IOException e) {
log.info("Refused connection | Does not exist:" + link.getLink());
notValid = true;
}
if (notValid) {
link.setApproved(false);
link.setDateApproved(null);
notValidLinks.add(linkService.save(link));
}
log.debug("URL Finieshed!");
}
}发布于 2010-11-17 16:24:06
查看Bloom Filter [wiki].This将帮助您快速和内存高效地看布隆过滤器的问题是,它将误报,即ups.The。对于不是there.But的东西,它会告诉true,如果布隆过滤器说false,那肯定是false。
发布于 2010-11-17 12:27:26
我想改进它,这样它就可以检测到所有无效的页面,包括出售的域名。
我怀疑突出显示的部分不切实际。蜘蛛是如何辨别域名是否出售的呢?
后续
@Mat Banik建议寻找特定的短语或检查DNS记录作为可能的解决方案。
检查特定短语的启发式方法会给出误报和错误的negatives.
但是我想,如果你准备接受一些假阳性和阴性,那么尝试过滤掉出售的域名是可行的。
https://stackoverflow.com/questions/4201255
复制相似问题