本文整理汇总了Java中com.crawljax.core.configuration.CrawljaxConfiguration.builderFor方法的典型用法代码示例。如果您正苦于以下问题:Java CrawljaxConfiguration.builderFor方法的具体用法?Java CrawljaxConfiguration.builderFor怎么用?Java CrawljaxConfiguration.builderFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.crawljax.core.configuration.CrawljaxConfiguration
的用法示例。
在下文中一共展示了CrawljaxConfiguration.builderFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
public static void main(String[] args) {
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor("http://demo.crawljax.com/");
builder.addPlugin(new OnNewStatePlugin() {
@Override
public void onNewState(CrawlerContext context, StateVertex newState) {
// This will print the DOM when a new state is detected. You should see it in your
// console.
LOG.info("Found a new dom! Here it is:\n{}", context.getBrowser().getStrippedDom());
}
@Override
public String toString() {
return "Our example plugin";
}
});
CrawljaxRunner crawljax = new CrawljaxRunner(builder.build());
crawljax.call();
}
示例2: main
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
/**
* Run this method to start the crawl.
*/
public static void main(String[] args) {
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor("http://demo.crawljax.com/");
// Add the invariant that checks that the string isn't present.
builder.crawlRules().addInvariant(
"Detect a string",
new NotRegexCondition(
"Invariants can be used to perform tests on the current state"));
// This plugin will just print the error.
builder.addPlugin(new OnInvariantViolationPlugin() {
@Override
public void onInvariantViolation(Invariant invariant, CrawlerContext context) {
LOG.error("\n\n!!! Invariant {} violated !!!\n", invariant);
}
});
CrawljaxRunner crawljax = new CrawljaxRunner(builder.build());
crawljax.call();
}
示例3: main
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
/**
* Entry point
*/
public static void main(String[] args) {
CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(URL);
builder.crawlRules().insertRandomDataInInputForms(false);
builder.crawlRules().click("a");
builder.crawlRules().click("button");
// except these
builder.crawlRules().dontClick("a").underXPath("//DIV[@id='guser']");
builder.crawlRules().dontClick("a").withText("Language Tools");
// limit the crawling scope
builder.setMaximumStates(MAX_NUMBER_STATES);
builder.setMaximumDepth(MAX_DEPTH);
builder.addPlugin(new SamplePlugin());
builder.crawlRules().setInputSpec(getInputSpecification());
CrawljaxRunner crawljax = new CrawljaxRunner(builder.build());
crawljax.call();
}
示例4: getCrawljaxConfiguration
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
/**
* retrieve / build the CrawljaxConfiguration for the given arguments.
*/
protected CrawljaxConfiguration getCrawljaxConfiguration() {
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor(WEB_SERVER.getSiteUrl());
builder.crawlRules().waitAfterEvent(getTimeOutAfterEvent(), TimeUnit.MILLISECONDS);
builder.crawlRules()
.waitAfterReloadUrl(getTimeOutAfterReloadUrl(), TimeUnit.MILLISECONDS);
builder.setMaximumDepth(3);
builder.crawlRules().clickOnce(true);
builder.setBrowserConfig(getBrowserConfiguration());
addCrawlElements(builder);
builder.crawlRules().setInputSpec(getInputSpecification());
addCrawlConditions(builder);
addOracleComparators(builder);
addInvariants(builder);
addWaitConditions(builder);
addPlugins(builder);
return builder.build();
}
示例5: testExtract
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
@Test
public void testExtract() throws InterruptedException, CrawljaxException {
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor(DEMO_SITE_SERVER.getSiteUrl().toExternalForm());
builder.crawlRules().click("a");
builder.crawlRules().clickOnce(true);
CrawljaxConfiguration config = builder.build();
CandidateElementExtractor extractor = newElementExtractor(config);
browser.goToUrl(DEMO_SITE_SERVER.getSiteUrl());
List<CandidateElement> candidates = extractor.extract(DUMMY_STATE);
assertNotNull(candidates);
assertEquals(15, candidates.size());
}
示例6: testExtractExclude
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
@Test
public void testExtractExclude() throws Exception {
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor(DEMO_SITE_SERVER.getSiteUrl().toExternalForm());
builder.crawlRules().click("a");
builder.crawlRules().dontClick("div").withAttribute("id", "menubar");
builder.crawlRules().clickOnce(true);
CrawljaxConfiguration config = builder.build();
CandidateElementExtractor extractor = newElementExtractor(config);
browser.goToUrl(DEMO_SITE_SERVER.getSiteUrl());
List<CandidateElement> candidates = extractor.extract(DUMMY_STATE);
assertNotNull(candidates);
assertThat(candidates, hasSize(11));
}
示例7: testExtractIframeContents
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
@Test
public void testExtractIframeContents() throws Exception {
RunWithWebServer server = new RunWithWebServer("/site");
server.before();
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration
.builderFor(server.getSiteUrl().toExternalForm() + "iframe/");
builder.crawlRules().click("a");
CrawljaxConfiguration config = builder.build();
CandidateElementExtractor extractor = newElementExtractor(config);
browser.goToUrl(new URL(server.getSiteUrl().toExternalForm() + "iframe/"));
List<CandidateElement> candidates = extractor.extract(DUMMY_STATE);
for (CandidateElement e : candidates) {
LOG.debug("candidate: " + e.getUniqueString());
}
server.after();
assertNotNull(extractor);
assertNotNull(candidates);
assertThat(candidates, hasSize(9));
}
示例8: newCrawlConfigurationBuilder
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
/**
* Override this method to specify a different configuration.
*
* @return a new {@link CrawljaxConfiguration} to crawl with.
*/
protected CrawljaxConfigurationBuilder newCrawlConfigurationBuilder() {
CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(getUrl());
builder.crawlRules().clickDefaultElements();
builder.setUnlimitedRuntime();
builder.setUnlimitedCrawlDepth();
builder.addPlugin(new PostCrawlStateGraphChecker());
return builder;
}
示例9: testPopups
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
@Test
public void testPopups() throws CrawljaxException {
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor(WEB_SERVER.getSiteUrl().toExternalForm()
+ "popup");
builder.setMaximumDepth(3);
builder.crawlRules().click("a");
builder.crawlRules().waitAfterEvent(100, TimeUnit.MILLISECONDS);
builder.crawlRules().waitAfterReloadUrl(100, TimeUnit.MILLISECONDS);
CrawljaxRunner runner = new CrawljaxRunner(builder.build());
CrawlSession session = runner.call();
assertThat(session.getStateFlowGraph(), hasEdges(2));
assertThat(session.getStateFlowGraph(), hasStates(3));
}
示例10: setupConfig
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
protected CrawljaxConfigurationBuilder setupConfig() {
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor(WEB_SERVER.getSiteUrl().toExternalForm()
+ "iframe");
builder.crawlRules().waitAfterEvent(100, TimeUnit.MILLISECONDS);
builder.crawlRules().waitAfterReloadUrl(100, TimeUnit.MILLISECONDS);
builder.setMaximumDepth(3);
builder.crawlRules().click("a");
builder.crawlRules().click("input");
return builder;
}
示例11: testDontClickUnderXPath
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
@Test
public void testDontClickUnderXPath() throws Exception {
String url = "http://localhost:" + port + "/infinite.html";
CrawljaxConfigurationBuilder builder =
CrawljaxConfiguration.builderFor(url);
builder.setMaximumStates(3);
builder.setBasicAuth(USERNAME, PASSWORD);
CrawlSession session = new CrawljaxRunner(builder.build()).call();
assertThat(session.getStateFlowGraph(), hasStates(3));
}
示例12: main
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
/**
* Run this method to start the crawl.
*
* @throws IOException
* when the output folder cannot be created or emptied.
*/
public static void main(String[] args) throws IOException {
CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(URL);
builder.crawlRules().insertRandomDataInInputForms(false);
builder.setMaximumRunTime(100, TimeUnit.SECONDS);
// click these elements
builder.crawlRules().clickDefaultElements();
builder.crawlRules().click("div").withAttribute("class", "clickable");
// but don't click these
builder.crawlRules().dontClick("a").withAttribute("class", "ignore");
builder.crawlRules().dontClick("a").underXPath("//DIV[@id='footer']");
// Set timeouts
builder.crawlRules().waitAfterReloadUrl(WAIT_TIME_AFTER_RELOAD, TimeUnit.MILLISECONDS);
builder.crawlRules().waitAfterEvent(WAIT_TIME_AFTER_EVENT, TimeUnit.MILLISECONDS);
// Add a condition that this XPath doesn't exits
builder.crawlRules().addCrawlCondition("No spans with foo as class",
new NotXPathCondition("//*[@class='foo']"));
// Set some input for fields
builder.crawlRules().setInputSpec(getInputSpecification());
// This will generate a nice output in the output directory.
File outFolder = new File("output");
if (outFolder.exists()) {
FileUtils.deleteDirectory(outFolder);
}
builder.setOutputDirectory(outFolder);
builder.addPlugin(new CrawlOverview());
// We want to use two browsers simultaneously.
builder.setBrowserConfig(new BrowserConfiguration(BrowserType.FIREFOX, 1));
CrawljaxRunner crawljax = new CrawljaxRunner(builder.build());
crawljax.call();
}
示例13: readConfig
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
private CrawljaxConfiguration readConfig(String urlValue, String outputDir) {
CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(urlValue);
builder.setOutputDirectory(new File(outputDir));
BrowserType browser = BrowserType.FIREFOX;
if (options.specifiesBrowser()) {
browser = options.getSpecifiedBrowser();
}
int browsers = 1;
if (options.specifiesParallelBrowsers()) {
browsers = options.getSpecifiedNumberOfBrowsers();
}
if (browser == BrowserType.REMOTE) {
String remoteUrl = options.getSpecifiedRemoteBrowser();
builder.setBrowserConfig(BrowserConfiguration.remoteConfig(browsers, remoteUrl));
} else {
builder.setBrowserConfig(new BrowserConfiguration(browser, browsers));
}
if (options.specifiesDepth()) {
builder.setMaximumDepth(options.getSpecifiedDepth());
}
if (options.specifiesMaxStates()) {
builder.setMaximumStates(options.getMaxStates());
}
if (options.requestsCrawlHiddenAnchors()) {
builder.crawlRules().crawlHiddenAnchors(true);
}
configureTimers(builder);
builder.addPlugin(new CrawlOverview());
if (options.specifiesClickElements()) {
builder.crawlRules().click(options.getSpecifiedClickElements());
} else {
builder.crawlRules().clickDefaultElements();
}
return builder.build();
}
示例14: newConfigBuilder
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
public CrawljaxConfigurationBuilder newConfigBuilder() {
return CrawljaxConfiguration.builderFor(getSiteUrl());
}
示例15: setupBuilder
import com.crawljax.core.configuration.CrawljaxConfiguration; //导入方法依赖的package包/类
public CrawljaxConfigurationBuilder setupBuilder(String url) {
CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(url);
return builder;
}