0

Here I have a some HTML code and I need to 1st. load url source code then type xpath and as a result get a some text from that URL based on xPath... How to do that... with jquery, ajax ... ???

http://jsfiddle.net/cHtWq/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<label>Enter URL address here: 
<input name="textfield" type="text" value="http://www." />
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
<br />
<br />
Enter xpath location of element:
<input type="text" name="textfield2" />
<input type="submit" name="Submit2" value="Submit" />
<br />
<br />
Selected element is: </label>
<p>&nbsp;</p>
</body>
</html>
Miki Cloud
  • 53
  • 1
  • 2
  • 5

1 Answers1

1

You cannot do this in JavaScript because of the Same Origin Policy you will need some back end scripting to do this.

Manse
  • 37,765
  • 10
  • 83
  • 108
  • I think it can be possiblle with ajax – Miki Cloud Feb 15 '12 at 17:21
  • 1st load source code when I type URL and click on submit then I write a xpath location and as a result get a text – Miki Cloud Feb 15 '12 at 17:22
  • @MikiCloud AJAX isn't magic ... it has to adhere to the the same security policy ... you can do cross domain AJAX but using JSONP only ... – Manse Feb 15 '12 at 17:23
  • Ok how I can do that with JSON? – Miki Cloud Feb 15 '12 at 17:23
  • please Help and I will appreciate to donate some money on your paypal account HELP! – Miki Cloud Feb 15 '12 at 17:24
  • JSON will not help you here - what you need is a backend script - PHP for example would be able to do this very easily ... http://stackoverflow.com/questions/2571232/parse-html-with-phps-html-domdocument – Manse Feb 15 '12 at 17:30
  • What are you trying to find on a remote site ? – Manse Feb 15 '12 at 17:31
  • yes I have that php file for parse html but NOW i need to combine php file and the second file above to get script... but How to do that... json, how to connect this two files – Miki Cloud Feb 15 '12 at 17:32
  • I try to get some text based on my xpath – Miki Cloud Feb 15 '12 at 17:37
  • Have a look at this question / answer - http://stackoverflow.com/questions/2571232/parse-html-with-phps-html-domdocument its exactly what you want to do ... – Manse Feb 16 '12 at 09:45