javascript - Phantomjs cannot open a page that browser opens -


i have phantomjs script tries open url. phantomjs returns error:

unable load resource (request id:undefinedurl:http://foo.bar/tree/nav_value/27) error code: 203. description: error downloading http://foo.bar/tree/nav_value/27 - server replied: not found 

but when open url http://foo.bar/tree/nav_value/27 chrome browser, there's no problem , page loaded correctly!

this script:

// read phantom webpage '#intro' element text using jquery , "includejs"  "use strict"; var page = require('webpage').create(); var system = require('system');  if (system.args.length != 2) {     console.log("please pass 2 argument") } var company_id = system.args[1] console.log("c", company_id)  page.onconsolemessage = function(msg) {     console.log("message", msg); };  page.onresourceerror = function(resourceerror) {     console.log('unable load resource (request id:' + resourceerror.id + 'url:' + resourceerror.url + ')');     console.log('error code: ' + resourceerror.errorcode + '. description: ' + resourceerror.errorstring);  };  page.onerror = function(msg, trace) {     console.log("error", msg) }  var nav_value;  page.open("http://foo.bar/tree/nav_value/27", 'post', 'username=navid&password=test', function(status) {     if (status === "success") {         page.includejs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {             page.evaluate(function() {                 nav_value = parseint($("#value").text());             });             phantom.exit(0);         });     } else {       phantom.exit(1);     } }); 

edit:

something odd happens. when run code phantomjs on windows on machine works. on ubuntu returns error!

the url phantomjs trying open on same server. (ubuntu)

what problem?

not sure help, have ideas helped me figure out problems phantomjs in past.

first, works on machine, may want test other versions of phantomjs, downloading executable , specifying path on python script. version 1.9.8 helped me bypassing security restrictions in past (i left settings in case may interest).

driver = webdriver.phantomjs(     executable_path='/path/to/the/downloaded/phantomjs19',     # can specify args, such as:     service_args=[         '--ignore-ssl-errors=true',          '--ssl-protocol=any',          '--web-security=false',     ],     # , other capabilities:     desired_capabilities={         'phantomjs.page.settings.resourcetimeout': '5000',         'phantomjs.page.settings.useragent': (             "mozilla/5.0 (x11; linux x86_64) applewebkit/53 "             "(khtml, gecko) chrome/15.0.87"         ),     }, ) 

you may try see if upgrading selenium helps.

pip install selenium --upgrade 

another idea might understand happening try print screenshot , log page source before error happens. can like:

# set window size appropriate tests. driver.set_window_size(900, 800) driver.save_screenshot('screen.png')  # check if page source matches expectations. open('temp.html', 'w') f:     f.write(driver.page_source) 

please, let me know if helps!


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -