搜索引擎及搜索引擎优化(SEO)实验 - 图文(6)

2019-03-23 14:36

messageArea.append(\ Bad URL encountered : \ }

catch(IOException e) {

messageArea.append(\\

} yield(); return; } /**

* Stops the search. */

public void stopSearch() {

stopSearch = true; } /**

* Inner class used to html handle parser callbacks */

public class SpiderParserCallback extends HTMLEditorKit.ParserCallback { /** url node being parsed */ private UrlTreeNode node; /** tree node */

private DefaultMutableTreeNode treenode; /** contents of last text element */ private String lastText = \ /**

* Creates a new instance of SpiderParserCallback * @param atreenode search tree node that is being parsed */

public SpiderParserCallback(DefaultMutableTreeNode atreenode) {

IOException,

could

not

access

site

:

26

treenode = atreenode;

node = (UrlTreeNode)treenode.getUserObject(); } /**

* handle HTML tags that don't have a start and end tag * @param t HTML tag * @param a HTML attributes * @param pos Position within file */

public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {

if(t.equals(HTML.Tag.IMG)) {

node.addImages(1); return; }

if(t.equals(HTML.Tag.BASE)) {

Object value = a.getAttribute(HTML.Attribute.HREF); if(value != null)

node.setBase(fixHref(value.toString())); } } /**

* take care of start tags * @param t HTML tag * @param a HTML attributes * @param pos Position within file */

public void handleStartTag(HTML.Tag t,

MutableAttributeSet a, int pos)

27

{

if(t.equals(HTML.Tag.TITLE)) {

lastText=\ return; }

if(t.equals(HTML.Tag.A)) {

Object value = a.getAttribute(HTML.Attribute.HREF); if(value != null) {

node.addLinks(1);

String href = value.toString(); href = fixHref(href); try{

URL referencedURL = new URL(node.getBase(),href); searchWeb(treenode,

referencedURL.getProtocol()+\

}

catch (MalformedURLException e) {

messageArea.append(\ Bad URL encountered : \ return; } } } } /**

* take care of start tags * @param t HTML tag

* @param pos Position within file */

public void handleEndTag(HTML.Tag t,

28

int pos) {

if(t.equals(HTML.Tag.TITLE) && lastText != null) {

node.setTitle(lastText.trim());

DefaultTreeModel tm = (DefaultTreeModel)searchTree.getModel(); tm.nodeChanged(treenode); } } /**

* take care of text between tags, check against keyword list for matches, if * match found, set the node match status to true * @param data Text between tags

* @param pos position of text within web page */

public void handleText(char[] data, int pos) {

lastText = new String(data); node.addChars(lastText.length()); String text = lastText.toUpperCase(); for(int i = 0; i < keywordList.length; i++) {

if(text.indexOf(keywordList[i]) >= 0) {

if(!node.isMatch()) {

sitesFound++; updateStats(); }

node.setMatch(keywordList[i]); return; } } }

29

} } /*

* SpiderControl.java * */

import java.awt.*; import javax.swing.*; import javax.swing.tree.*; import java.util.*; import java.net.*; /**

* User interface to conduct web searches with the Spider object * @author Mark Pendergast */

public class SpiderControl extends javax.swing.JFrame implements VerifierListener{

/** Creates new form SpiderControl */ public SpiderControl() { initComponents(); setSize(650,600);

setTitle(\ //

// center the frame on the screen //

Dimension oursize = getSize();

Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();

int x = (screensize.width - oursize.width)/2; int y = (screensize.height- oursize.height)/2; x = Math.max(0,x); // keep the corner on the screen y = Math.max(0,y); //

30


搜索引擎及搜索引擎优化(SEO)实验 - 图文(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:小学数学第12册第一单元测试题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: