This question already has answers here:
Simple Screen Scraping using jQuery
(7 answers)
Closed 5 years ago.
I want to get data from other url which is product info. I want to scrape all of this data for this attribute:
$('[data-b-for-cart]').attr('data-b-for-cart');
And want to export that to csv file.
Not sure hows this should be done any resource would be helpful.
I think I should use the jquery $.get is that right ?
you can try ajax within jquery to scrape. It is not that difficult
$(document).ready(function() {
baseUrl = "http://www.somedomain.com/";
$.ajax({
url: baseUrl,
type: "get",
dataType: "",
success: function(data) {
//do something with data and save as csv file
}
});
});
Related
This question already has answers here:
How do I get the different parts of a Flask request's url?
(4 answers)
jQuery posting JSON
(3 answers)
How to get POSTed JSON in Flask?
(13 answers)
Closed 4 years ago.
!! THIS IS NOT A DUPLICATE !!
The question was not how to get an URL in Flask, but how to send data with jQuery to Flask!
I try to send and receive data with python, Flask and jQuery
The problem is that I want the full URL of the website and it is impossible to get it with flask because I make 'POST' requests. So with jQuery, I want to send the current URL.
I don't know how to send data (with jQuery) and receive data (with Flask).
Python/Flask code:
#app.route('/invisible', methods = ['POST'])
def dynamic_refresh():
return jsonify({'somedata': 'data'})
HTML/jQuery code:
<script>
$(document).ready(function() {
window.setInterval(function() {
$.ajax({
type : 'POST',
url : '/invisible',
//I tried to send data from here but it didn't worked
})
.done(function(data) {
console.log(data)
console.log(window.location.href)//the url I want to send
//here I use the data received by the server
})
}, 5000);
});
</script>
Its quite simple, enclose data in JSON array which you want to send through POST request and then retrieve any data from Flask endpoint like this;
var url = $('#url').val().trim(); //get your value from HTML here
var params = {
_url: url,
};
var array = JSON.stringify(params); //enclosed it in json array
$.ajax({
type: "POST",
url: "/invisible",
data: array,
dataType: 'json',
success: function(results){
console.log(results)
}
});
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
How to make a simple JSONP asynchronous request in Angular 2?
(4 answers)
Closed 5 years ago.
I have a preblem about get json data form url
example url:
https://books.google.com/books?bibkeys=ISBN:1118691784,OCLC:879947237,LCCN:&jscmd=viewapi&callback=updateGBSCover
this url is give .txt and .txt have json data
I have no idea to get json data in .txt for show in page
Thanks for help me :)
The data is in JSONP format, e.g. JSON wrapped in a callback
More information here: https://developers.google.com/books/
$.ajax({
url: "https://books.google.com/books?bibkeys=ISBN:1118691784,OCLC:879947237,LCCN:&jscmd=viewapi",
dataType: "jsonp",
jsonpCallback: "updateGBSCover"
});
function updateGBSCover(data) {
// console.log(data);
$("#result").append($('<img/>',{"src": data["OCLC:879947237"].thumbnail_url}));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="result"></div>
This question already has answers here:
jQuery Ajax POST example with PHP
(17 answers)
Closed 7 years ago.
I'm trying to pass 3 variables that look like this
var location = document.location.pathname;
var search = document.location.search;
var referrer = document.referrer;
Into a PHP file that I can eventually use to send emails, I have never used AJAX before but know that you could use it to achieve this.
Can anyone help me out? Thanks in advance.
A simple Ajax POST method can help you here. Here's an example.
$.ajax({
type: "POST",
url: "ajax.php",
data: {location: location, search: search, referrer: referrer},
success: function(response){
//do something
}
})//ajax end
Now in ajax.php, you can receive the values via $_POST.
PHP Receiving(ajax.php).
var_dump($_POST['location']);
You could do like this:
$.ajax({
type: "POST",
data: {'location': location,
'search': search,
'referrer': referrer
},
url: "Here the path to your php-file",
success: function (data) {
Here you could react on any
}
});
In the php file you receive those data by Post and can handle them.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
HTTP GET request in Javascript?
I have a url that contains a XML tree. I want to read that url content, save it to a variable, extract XML tree values, and draw it in a table.
Use an AJAX query, in jQuery:
$.ajax({
url: url,
dataType: 'xml',
success: function(data) {
// Data is your xml content which you can work with
}
});
This question already has answers here:
Find where a t.co link goes to [closed]
(7 answers)
Closed 10 years ago.
How can I get the target URL for a Twitter t.co link that has been captured via the Twitter API using JavaScript.
e.g. http://t.co/NJwI2ugt
I made a fiddle here: http://jsfiddle.net/duotrigesimal/XB8Uf/
It makes a request to the api at LongURL (http://longurl.org/api#expand-url) to get the expanded url.
I'm also using jQuery in this example, but you can make it work without if needed.
var tests = [
'http://t.co/NJwI2ugt',
'http://www.google.com' //nothing should happen
];
for(i in tests) {
var data = {
url: tests[i],
format: 'json'
};
$.ajax({
dataType: 'jsonp',
url: 'http://api.longurl.org/v2/expand',
data: data,
success: function(response) {
$('#output').append(response['long-url']+'<br>');
}
});
}