7
Grab content from another page by javascript or jquery
On another question I wanted to know how to get content from a page.
In this I wanted through this code to catch only one <div>
instead of the entire content. Let’s assume that I wanted to take all the contents of a <div>
so-called test.
How to catch only one <div>
?
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="estilo.css">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://projetos.lucaspeperaio.com.br/ajax-cross-domain/jquery.xdomainajax.js"></script>
</head>
<body>
<script>
$.ajax({
url: 'http://agenciaroadie.com.br/loja.php',
type: 'GET',
success: function(res) {
var headline = $(res.responseText).text();
$("#cabecalho").html(headline);
}
});
</script>
<div id="cabecalho">
</div>
</body>
Very good, can you find tags or classes too? Or tags within an ID?
– Felipe Jorge
Yes, I quoted it above, but I did not put it in the example ^_^
– Wallace Maxters
@Wallace in this example would var html be the site address? example var html = www.google.com ?
– Paulo Roberto
No. It would be the content returned by AJAX. The function response
$.ajax
always falls in the first function parametersuccess
, which is represented by the variableresponse
. I will post example.– Wallace Maxters
In this subject ai I was floating even and did not understand, you care to post a full example there please, removing from the site http://www.pauloroberto.info a div wb_element_instance10, for I see this business working, I’ve given up on it in the past because I didn’t understand... If it won’t take up too much of your time.
– Paulo Roberto
One last question, how do I access the second read in the last element, assuming there are two read?
– Felipe Jorge
var $lis = $(html). find('#content > ul > li'); if I want to catch the second li
– Felipe Jorge
var $lis = $(html).find('#conteudo > ul > li').eq(1)
. For the counting of<li>
is fromzero
.– Wallace Maxters
Thanks, I found no tutorial on this, it will help a lot.
– Felipe Jorge