|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcs132.webSpider.Spider
public class Spider
This class provides implementation of a Spider or web crawler. The state of the web crawler consists of:
| Constructor Summary | |
|---|---|
Spider(boolean isDFS,
int limit,
java.lang.String root)
Create a new Web Spider |
|
| Method Summary | |
|---|---|
void |
addPageToCrawl(WebPage w)
Add a web page to the set of pages to be crawled |
WebPage |
addURLToCrawl(java.net.URL u)
Add the WebPage corresponding to a URL to the set of pages to crawl. |
void |
crawl(WebPage w)
Crawl one WebPage. |
WebPage |
getNextPageToCrawl()
Determines the web page that should next be crawled and removes it from the queue, skipping over any web pages that have already been visited. |
int |
getNumberOfPagesCrawled()
Return the count of the number of web pages crawled |
java.util.Collection<java.net.URL> |
getURLs()
Returns a collection of the URLs of all known webpages (e.g., the URL's corresponding to the WebPages returned by the getWebPages method). |
java.util.Collection<WebPage> |
getWebPages()
Returns a collection of all known web pages, including both visited and unvisited webpages |
WebPage |
lookupWebPage(java.net.URL u)
Given a URL, returns the corresponding web page corresponding to the normalized URL |
static void |
main(java.lang.String[] args)
Invoke the Spider, crawl 5 web pages in DFS order, and print the result |
void |
performCrawl()
Crawls all WebPages, adding more Webpages to the crawl queue as links to them are found. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Spider(boolean isDFS,
int limit,
java.lang.String root)
isDFS - --
should the spider perform a DFS crawl?limit - --
maximum number of web pages to crawlroot - --
root that limits extent of crawl. Only URLs that start with
this root will be crawled.| Method Detail |
|---|
public static void main(java.lang.String[] args)
throws java.lang.Exception
args - -
first element should be web page to start crawl from, second
element is the root of the web crawl (only URL's that start
with that root will be crawled).
java.lang.Exceptionpublic int getNumberOfPagesCrawled()
public void addPageToCrawl(WebPage w)
w - -
web page to crawl@CheckForNull public WebPage addURLToCrawl(java.net.URL u)
Util.shouldCrawlURL(URL, String) returns false, this method should simple return null.
Otherwise, the URL is first normalized, to remove anchors (such as
http://foo.com/bar.html#goo); this is done by the method Util.normalize(URL).
If the URL has not been added before, this method creates a new WebPage
object corresponding to the URL and remembers the association linking
the URL to that web page. Otherwise, it remembers the previously used WebPage.
If the WebPage has not yet been visited, the WebPage is added to
the collection of pages to crawl.
The WebPage corresponding to the URL is returned.
u - -
URL of page
public void performCrawl()
public java.util.Collection<WebPage> getWebPages()
public java.util.Collection<java.net.URL> getURLs()
public void crawl(WebPage w)
w - -
the web page to crawl@Nullable public WebPage getNextPageToCrawl()
@CheckForNull public WebPage lookupWebPage(java.net.URL u)
u - URL to lookup
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||