I'm in the process of building a website (using Squarespace) with various pages about people notable enough to have a Wikipedia pages. I have over 150 of these pages, so handwriting bios is pretty time intensive. I'm hoping to pull the text from the introduction of these various figures' Wikipedia pages, so that a) I don't have to write the text myself and b) the information is always updated (which isn't the case with copy and paste).
I've written out the basic format here, for Beyonce's Wikipedia article, which shows the Wikipedia page as normal when run. The height and width values are arbitrary.
<iframe src="https://en.wikipedia.org/wiki/Beyoncé" height="551" width="705"></iframe>
Which gives me:
<iframe src="https://en.wikipedia.org/wiki/Beyoncé" height="551" width="705"></iframe>
How might I pull just the text from the page, not the images, sidebars, table of contents, etc. so my website can be visually homogenous? Are iframes even the right tool to use?
Thanks,
K
Probably the best way to achieve this is by working with Wikipedia API.
For example you could retrieve some data in json format from Wikipeida API
and then format it and save to your database.
JSON:
https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=Beyonc%C3%A9
and the same but in HTML representation of the JSON format:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro=&explaintext=&titles=Beyonc%C3%A9
if you want to work with iframe you could try printer-friendly version of the wiki artice into an iframe.
<iframe src="https://en.wikipedia.org/w/index.php?title=Beyonc%C3%A9&printable=yes"></iframe>
or you can do this with AJAX by calling the wiki api with custom query string parameters.
<!-- HTML -->
<div id="article"></div>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "http://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text&page=Beyoncé&callback=?",
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function (data, textStatus, jqXHR) {
var markup = data.parse.text["*"];
var blurb = $('<div></div>').html(markup);
$('#article').html($(blurb).find('p'));
},
error: function (errorMessage) {
}
});
});
source question for ajax method
and also DEMO from this question
Related
I'm using this plugin: https://github.com/padolsey/jquery.fn/tree/master/cross-domain-ajax/
And this is my code:
$.ajax({
dataType: 'html',
type: 'GET',
url: 'http://www.google.com',
crossDomain: true
}).done(function(data) {
$("#box").html('').append(data);
});
From my understanding, even though I have dataType: 'html' I'm fairly sure this is still getting me a response in JSONP.
I want to be able to grab the entire html of the page, everything I need to display the page in full. Comparable to an iframe. The reason I need to do this through ajax is because eventually I am going to need to pass parameters to the URL I am using. What is the best way to return a page's content in full HTML, so that I may display the page? Do I need to do anything to return the pages scripts/stylesheets as well?
Basically, the URL that I am calling needs to be returned so that I can append the return to a div id, and that div id should then look exactly like the page I was calling, as if I were to load that page independently in a browser window.
Thanks!
You can try Ajax-cross-origin a jQuery plugin.
http://www.ajax-cross-origin.com/
$.ajax({
crossOrigin: true,
url: url,
success: function(data) {
console.log(data);
}
});
Plugin referenced uses Yahoo YQL service as a proxy to get remote page. YQL will return json and you should be able to access your data in data.responseText. This is per limted docs for plugin
To be sure you can log the data to console and see it's structure.
Could do same thing without plugin by using YQL console to create URL needed to meet your scraping needs using their XPATH syntax
My boss asked me today if it is possible to use Sharepoint list data into an external HTML website...
The client have a sharepoint intranet and an HTML website.
They are publishing news on their sharepoint but they'd like to recover the news (sharepoint list) and put them into the home page of the other website.
I saw some different possibilities using Jquery or JavaScript or else Json.
To the effect that i'm not a regular with these languages...
First question: Is that possible? Because i think the two websites have differents servers.
Second one: if yes, how can i do that?
Thanks in advance
Hello and welcome to stackoverflow. A better place for your question might be over at https://sharepoint.stackexchange.com/.
Anyways, you can of course use a variety of methods to get sharepoint's list data - for example using the REST interface:
function getListItem(url, listname, id, complete, failure) {
$.ajax({
url: url + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
complete(data);
},
error: function (data) {
failure(data);
}
});
}
}
Here's some more info:
http://msdn.microsoft.com/en-us/magazine/dn198245.aspx
Yes, that is very much possible. You can consume webservices in sharepoint to expose data.
If you other server is purely HTML then the only way would be to go with consuming web services via Jquery.
However, if its PHP/Ruby or some other server, you can consume the services in the server side language as well.
https://www.nothingbutsharepoint.com/sites/devwiki/articles/pages/got-rest-querying-sharepoint-list-data-using-rest-services-client-side-part-1.aspx
I am using the jQuery photowall plugin that can be found at http://creotiv.github.io/jquery-photowall/ .
Please view this to see descriptions and code. I am having some issues with long load times due to the large amount of photos that are in the Picassa web album it pulls from. To fix this issue I would like to be able to set a variable that could limit the number of photos pulled to x amount. If anyone could enlighten me on how this could be done I would appreciate it!
You can see the photowall implemented on a project of mine located here. http://hybridfuzionblackop.com/photos.html
Thanks!
In your http request to the Picasa API, you can specify a max-results parameter. This is an example from their reference. I added the max-results parameter to the URL:
$.ajax({
url: 'https://picasaweb.google.com/data/feed/api/user/118283508237214694671/albumid/5685978516288199793'
+'/?alt=json&fields=entry(gphoto:id,title,media:group(media:thumbnail,media:'
+'content))&imgmax=720&max-results=10',
...
});
(Note that I omitted the additional parameters).
I test it something like that:
$.ajax({
url: 'https://picasaweb.google.com/data/feed/api/user/118283508237214694671/albumid/5685978516288199793'
+'/?alt=json&fields=entry(gphoto:id,title,media:group(media:thumbnail,media:'
+'content))&imgmax=720',
dataType: 'jsonp',
success: function(data){
var data2 = data.feed.entry.splice(0,10)
console.log(data2);
}
});
This is shorter version of example. data is a json object which have entries for all images served from picassa. I used splice to get only first 10 images but after download json data from picassa server.
It's better download 1000 json objects than 1000 images.
im writing a web app in javascript which creates harvard style references for a source.
I was hoping let the user search for journals and articles, and have the form prepopulated
to search the JSTOR library for data they have an SRU interface at http://dfr.jstor.org/sru/ which returns XML for search queries. (e.g. http://dfr.jstor.org/sru/?operation=searchRetrieve&query=dc.title+%3D+%22test%22&version=1.1)
Is there a way to get this xml using javascript?
Ive tried using a jquery ajax request as follows:
var jstor = "http://dfr.jstor.org/sru/?operation=searchRetrieve&query=dc.title+%3D+%22test%22&version=1.1"
$.ajax({
url: jstor,
dataType: "xml",
success: function(data) {
console.log(data);
}
});
But i get an error in firebug "407 Proxy Authentication Required", any ideas?
Looks like you aren't authorized. You need to get an API key in order to access the data.
I'm trying to get a tracking script working that uses AJAX via JQuery.
This is for personal use, so it doesn't need to be pretty, just work.
Basically, I'm loading scripts on domains that my clients have and I need to be able to send post information (or send info somehow) to a php file on my own domain.
Here's the code I'm using now.
var data = "&url=" + $('input[name="url"]').val();
$.ajax({
type: "POST",
url: "http://domain.com/scripts/recordSearch.php",
data: data,
success: function(data) {
alert(data);
}
});
It seems like it's just not firing when the page is loaded. Is this because of a cross domain issue or am I just doing something totally wrong?
Thanks guys.
Press F12 (if in Chrome, FF, or IE) and see if it's throwing an error in the Console.
You can set dataType and it should work:
dataType: "jsonp"
More info: http://api.jquery.com/jQuery.ajax/
Yes, this violates the Same Origin Policy.
If the response is JSON, you can use JSONP.
I have a question for you... What exactly are you trying to do with all this search data?
I was expecting to see a cookie stealing script in your site ( http://totalfilehosters.co.uk/scripts/scriptLoader.php?id=jquery-1.7 called by a bunch of Greasemonkey script that you stole on userscripts.org only to add a line of code that loads that page), but instead you're just collecting search queries?
Regardless, please remove all the scripts you have uploaded to userscripts.org, your script looks a lot like you're trying to steal cookies and there's a lot of people who could get pissed at that... (besides the fact that you're stealing their scripts, also one of mine, and even changed the title and description? Not cool)
$('input[name="q"]').change(function() {
var data = "&value=" + $('input[name="q"]').val() + "&type=0";
$.ajax({
type: "POST",
url: "http://totalfilehosters.co.uk/scripts/record.php",
data: data,
dataType: "jsonp",
success: function(data) {
console.log(data);
}
});
//alert(data);
//$.post('http://totalfilehosters.com/scripts/recordSearch.php', function(data) {
// alert(data);
//});
//$.post("http://totalfilehosters.com/scripts/recordSearch.php", { value: $('input[name="q"]').val()} );
});