I try to get info from a website which uses Javascript to show onclick the phonenumber of the items/companies.
Crawling that with PHP curl or xpath did not let me find a solution how to trigger this events and than keep on crawling.
Example:
<a onclick="show(2423,'../entries.php?eid=2423',1);
for info here the function too
function show(info_id,qpath,swimage){
expandit(info_id,0,swimage);
if(document.getElementById('load_'+info_id)) {
ajax_loadContent('cont_td_'+info_id,qpath);
}
}
Is this possible to do with PHP/Xpath/DOM or what do you recommend to do to achieve this?
Any chance for "debugging" the code to see which url to call?
THanks for your concern
And have really great FESTIVITIES
It seems like all it's doing is an AJAX call to this page, ../entries.php?eid=2423.
Try going to that URL directly and you'll probably get your phone number without any HTML/JavaScript parsing.
You could use the net tab of firebug to keep an eye on what URLs are loaded. Or Fiddler. Once you work out the pattern you might be able to craft and call the same URLs yourself using curl.
Or, you could use one of the browser automation frameworks, like webaii or selenium or watir or watin and crawl the links that way.
Try using Selenium RC to simulate clicking on the link and then scan the page for results:
http://seleniumhq.org/projects/remote-control/
Related
I'm trying to make a Bookmarklet to grab an id value from the Clipboard, and navigate to a URL that is built with that id.
javascript:(function(){
window.location="index.php?module=Accounts&action=DetailView&record="
+ clipboardData.getData('Text');
})()
(this is only supposed to work when clicked on a specific site that is expecting that URL form)
The basics of the Bookmarklet are working fine, the tricky part is getting the Clipboard value, because clipboardData is not working.
I am using Firefox v64 (although I would like this to be generic across more browsers, at least modern ones).
Now, upon searching about this issue I realize what I'm trying to do is not as simple as it seems - clipboard API's in browsers are a tricky issue. I found several answers about this, the best one seems to be this:
JavaScript get clipboard data on paste event (Cross browser)
I also tried this one but couldn't get it to work either: https://stackoverflow.com/a/27908501/1189711
My question here is: are any of those techniques applicable in a Bookmarklet? If so, I would appreciate some help with this. My skills in Javascript are too low to understand how to translate these answers to my case - namely the asynchronous stuff.
PS - if someone wants a place to test this, just put 84f1bb99-7017-e8dc-94f9-5c179da9f102 in your clipboard and try it on this demo site, credentials will/will.
Clipboard copy cannot works from scripts. It must comes from an user action.
Similary, in the same way, you can't call a fullscreen from a bookmarklet.
From the Firefox console:
document.execCommand(‘cut’/‘copy’) was denied because it was not
called from inside a short running user-generated event handler.
I try this method and it works:
SAME WINDOWS:
javascript:location.href='https://www.ricerca.com?search%27+escape(location.href)
NEW WINDOWS: (by https://9to5answer.com/window-location-href-and-window-open-methods-in-javascript)
window.open()
javascript:window.open("https://www.ricerca.com?search="+window.getSelection());
I have some valuable processes on my site that I'd like to track regularly to make sure they are working. I wrote some javascript that will run the actions if the starting page contains a particular parameter, but I can't figure out how to properly execute the script without opening the page in a browser.
My best guess is I need some sort of chron driven bot for this, but I don't even know where I should begin with that and haven't found anything in my searching. I tried a cURL request, but it doesn't seem to fire the js. Really, if I could just find a way to properly initialize the js with a chron job that would be sufficient.
The key here is that I need it to execute the javascript so I can imitate user actions.
I'm working on a WordPress install, so it would need to be a php or javascript based solution. How can I build something like this?
Use an interaction testing framework like Ember.js. that should allow you to test your UI Interactions.
See the link above to get some detailed information on how to use the library.
Here is a code snippet from the Ember.js library to see if a user is
redirected properly if not authenticated (100% javascript!):
module('Integration: Transitions', {
teardown: function() {
App.reset();
}
});
test('redirect to login if not authenticated', function() {
visit('/');
click('.profile');
andThen(function() {
equal(currentRouteName(), 'login');
equal(currentPath(), 'login');
equal(currentURL(), '/login');
});
});
Ember.js is an excellent way to test your user interactions and your UI components.
Learn more here: http://emberjs.com/guides/testing/testing-user-interaction/
UPDATE:
See this answer for another solution that combines CasperJS and PhantomJS to test user interfaces.
Good luck!
If you don't want to have a browser open to do it you could use a headless browser like PhantomJS
I'm trying to set the value of a textarea on the following page by executing something similar the below javascript:
javascript:alert(document.getElementsByClassName('uiTextareaNoResize uiTextareaAutogrow _1rv DOMControl_placeholder')[0].value='blabla');
This works if I manually enter the code into the address bar on the target page, but I want to pass this argument through a link.. ie...
<a href="/nextpage.php?javascript:alert(document.getElementsByClassName('uiTextareaNoResize uiTextareaAutogrow _1rv DOMControl_placeholder')[0].value='blabla');"
Just wondered if anything like this is possible at all?
You can send the arguments via the url like you would for GET requests. Then have the receiving page parse location.search.
For instance, you can send it like this:
http://example.com/?arg1=foo&arg2=bar
And the receiving page have a script like this:
var queryString = location.search; //?arg1=foo&arg2=bar
You'll have to parse it manually though, removing the ?, split by & then each by =
This is called XSS or Cross-Site-Scripting, and as many comments have already pointed out, it is a security issue. This is why most major browsers do NOT allow it.
However, I believe that some browsers do allow it, for example Opera - although I can't recall exactly which version.
If you are looking to make your own "browser", I would recommend using C# .Net WebBrowser, then use the runtime package XULRunner (https://developer.mozilla.org/en-US/docs/Mozilla/Projects/XULRunner).
Despite all this, I would not recommend doing anything that may be against laws of your current location, or doing anything to displease the site owner.
I'm doing a couple of things with jQuery in an MTurk HIT, and I'm guessing one of these is the culprit. I have no need to access the surrounding document from the iframe, so if I am, I'd like to know where that's happening and how to stop it!
Otherwise, MTurk may be doing something incorrect (they use the 5-character token & to separate URL arguments in the iframe URL, for example, so they DEFINITELY do incorrect things).
Here are the snippets that might be causing the problem. All of this is from within an iframe that's embedded in the MTurk HIT** (and related) page(s):
I'm embedding my JS in a $(window).load(). As I understand it, I need to use this instead of $(document).ready() because the latter won't wait for my iframe to load. Please correct me if I'm wrong.
I'm also running a RegExp.exec on window.location.href to extract the workerId.
I apologize in advance if this is a duplicate. Indeed - after writing this, SO seems to have a made a good guess at this: Debugging "unsafe javascript attempt to access frame with URL ... ". I'll answer this question if I figure it out before you do.
It'd be great to get a good high-level reference on where to learn about this kind of thing. It doesn't fit naturally into any topic that I know - maybe learn about cross-site scripting so I can avoid it?
** If you don't know, an MTurk HIT is the unit of work for folks doing tasks on MTurk. You can see what they look like pretty quick if you navigate to http://mturk.com and view a HIT.
I've traced the code to the following chunk run within jquery from the inject.js file:
try {
isHiddenIFrame = !isTopWindow && window.frameElement && window.frameElement.style.display === "none";
} catch(e) {}
I had a similar issue running jQuery in MechanicalTurk through Chrome.
The solution for me was to download the jQuery JS files I wanted, then upload them to the secure amazon S3 service.
Then, in my HIT, I called the .js files at their new home at https://s3.amazonaws.com.
Tips on how to make code 'secure' by chrome's standards are here:
http://developer.chrome.com/extensions/contentSecurityPolicy.html
This isn't a direct answer to your question, but our lab has been successful at circumventing (read hack) this problem by asking workers click on a button inside the iframe that opens a separate pop-up window. Within the pop-up window, you're free to use jQuery and any other standard JS resources you want without triggering any of AMT's security alarms. This method has the added benefit of allowing workers to view your task in a full-sized browser window instead of AMT's tiny embedded iframes.
I want to implement a JavaScript API to initiate phone calls programmatically and without the need for a native Objective-C implementation.
What I tried so far was something like location.href='tel:12345';. The result was an error with the message "The URL can’t be shown".
My second attempt was to create a hidden link (like call) and click it programmatically. This didn't work either, although the link worked when not hidden and clicked manually by the user.
Is it possible to achieve this with JavaScript only or do I need to delegate to the Objective-C part of the application to initiate the call from there?
Instead of tel:12345 have you tried tel://12345 ?
call
Is your url is correct?
Use window.open() for this:
window.open( 'tel:800-888-1234', '_top' );
You will probably have to write the code to do so natively and create a JavaScript function to be called from within the WebView.