htmlunit

Can i use HtmlUnit to listen for resource loading events?

女生的网名这么多〃 提交于 2020-01-05 03:00:06
问题 I'm trying to use HtmlUnit to detect resources (scripts, images, stylesheets, etc) that fail to load on a webpage. I've tried new WebConnectionWrapper(webClient) { @Override public WebResponse getResponse(WebRequest request) throws IOException { WebResponse response; response = super.getResponse(request); System.out.println(response.getStatusCode()); return response; } }; to no avail. It doesn't seem to handle CSS, images or JS, despite HtmlUnit logging: statusCode=[404] contentType=[text

best way to parse google custom search engine results

谁说胖子不能爱 提交于 2020-01-04 06:39:05
问题 I need to parse through the results of google custom search engine. My first issue is that it is all in javascript. below page loads the results to be parsed, which opens in a js popup. <script> function gcseCallback() { if (document.readyState != 'complete') return google.setOnLoadCallback(gcseCallback, true); google.search.cse.element.render({gname:'gsearch', div:'results', tag:'searchresults-only', attributes:{linkTarget:''}}); var element = google.search.cse.element.getElement('gsearch');

HtmlUnit and Fragment Identities

非 Y 不嫁゛ 提交于 2020-01-03 15:38:38
问题 I'm currently wondering how to deal with fragment identities, a link that I am wanting to grab information from, contains a fragment identity. It seems as if HtmlUnit is discarding the "#/db4mj" of my url and therefore loading the original url. Does anyone know of a way to deal with fragment identities? (I can post example code to further explain if need be) EDIT Since I wasn't getting many views (and no answers), I'm going to add a bounty. Sorry it's only 50, but I only had 79 to start with

How do I get HtmlUnit to work under Android?

浪子不回头ぞ 提交于 2020-01-03 11:58:38
问题 Here is my code: import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlPage; final WebClient webClient = new WebClient(); final HtmlPage startPage = webClient.getPage("http://htmlunit.sf.net"); And this is the error I get: 11-04 21:58:08.761: ERROR/dalvikvm(17868): Could not find class 'com.gargoylesoftware.htmlunit.DefaultCssErrorHandler', referenced from method com.gargoylesoftware.htmlunit.WebClient.<init> 11-04 21:58:08.771: ERROR/dalvikvm(17868):

HtmlUnit and XPath: DOMNode.getByXPath only works on HtmlPage?

南笙酒味 提交于 2020-01-03 03:32:12
问题 I'm trying to parse a page with links to articles whose important content looks like this: <div class="article"> <h1 style="float: none;"><a href="performing-arts">Performing Arts</a></h1> <a href="/performing-arts/EIF-theatre-review-Sin-Sangre.6517348.jp"> <span class="mth3"> <span id="wctlMiniTemplate1_ctl00_ctl00_ctl01_WctlPremiumContentIcon1"> </span> EIF theatre review: Sin Sangre | The Man Who Fed Butterflies | Caledonia | Songs Of Ascension | Vieux Carré | The Gospel At Colonus </span>

how to get text between a specific span with HtmlUnit

…衆ロ難τιáo~ 提交于 2020-01-02 04:49:09
问题 I'm new to HtmlUnit and I'm not even sure if it is the right tool for my project. I'm trying to parse a website and extract the values I need from it. I need to get the value "07:05" from this, <span class="tim tim-dep">07:05</span> I know that I can use the getTextContent() for extracting the value but I don't know how I can select a specific span. I used getElementById for finding the <div> tag that this expression belongs to but when I get the text content of that div, I get a whole line

HTMLUnit executing form with javascript code

若如初见. 提交于 2019-12-31 04:26:06
问题 All i want to do is remotely ask a question on ask.fm using java nad HTMLUnit framework. I think it doesn't work because of the javascript code, but i'm not sure. this is how the ask question form looks like : <form action="/userame/questions/create" autocomplete="off" id="question_form" method="post" onsubmit="$.ajax({data:$.param($(this).serializeArray()) + '&authenticity_token=' + encodeURIComponent('b9o8BHnVU6KDQ/oMsdQh+ClYPlS10134bpa7bFCkqtA='), dataType:'script', type:'post', url:'

Error Executing javascript using HtmlUnit

梦想的初衷 提交于 2019-12-30 07:09:09
问题 I am trying to execute a JavaScript on the following URL: http://steamcommunity.com/id/bobcatchris/inventory#730 . I can do it using google chrome by opening console by pressing ctrl+shift+j and pasting the following script: var list = []; var size = Object.keys(g_ActiveInventory.rgInventory).size(); var counter = 0; while (counter < size) { list.push(g_ActiveInventory.rgInventory[Object.keys(g_ActiveInventory.rgInventory)[counter]].market_name); counter +=1; } It returns: 150 Then in the

Accessing html generated by Javascript with htmlunit -Java

只愿长相守 提交于 2019-12-30 04:00:09
问题 I am trying to be able to test a website that uses javascript to render most of the HTML. With the HTMLUNIT browser how would you be able to access the html generated by the javascript? I was looking through their documentation but wasn't sure what the best approach might be. WebClient webClient = new WebClient(); HtmlPage currentPage = webClient.getPage("some url"); String Source = currentPage.asXml(); System.out.println(Source); This is an easy way to get back the html of the page but would

Passing basic auth credentials with every request with HtmlUnit WebClient

杀马特。学长 韩版系。学妹 提交于 2019-12-30 03:18:08
问题 I'm trying to write a simple smoke test for a web application. The application normally uses form based authentication, but accepts basic auth as well, but since the default is form based authentication, it never sends an authentication required, but instead just sends the login form. In the test I try to send the basic auth header using WebClient webClient = new WebClient(); DefaultCredentialsProvider creds = new DefaultCredentialsProvider(); // Set some example credentials creds