Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Scraping page info ( ie image ) from a link entered
Old 10-16-2011, 05:27 AM Scraping page info ( ie image ) from a link entered
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Hi all

I have an form that requires a user to enter a url.

When the user has entered the url i want to extract from the url ( page ) entered a page image and title.

How do i do this please.?

( for those that use facebook, i require to do very similar as they have when you paste a url into a input field. )

Thanks if anyone can help. Any input would really be appreciated.

Cheers

Steve
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 10-16-2011, 05:56 AM Re: Scraping page info ( ie image ) from a link entered
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Using Javascript???
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 10-16-2011, 05:57 AM Re: Scraping page info ( ie image ) from a link entered
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
The first problem is a colelction level so yes js/jquery
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 10-16-2011, 06:58 AM Re: Scraping page info ( ie image ) from a link entered
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Unless the URL entered is on the same domain as the javascript is, it won't work.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-16-2011, 07:48 AM Re: Scraping page info ( ie image ) from a link entered
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
How does facebook do it then.
B eside which i have in the past read something on it.
Must be a way of getting url, and doing something like ajax to returve metta data.
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 10-16-2011, 08:46 AM Re: Scraping page info ( ie image ) from a link entered
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The URL will be passed to some server side code to get the data from the remote host.


Javascript is blocked from accessing URIs on remote hosts to prevent XSS/CSS (Cross Site Scripting) exploits/attacks/hijacks
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-16-2011, 09:20 AM Re: Scraping page info ( ie image ) from a link entered
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
You could always use an AJAX call to do it in PHP. Then return the result to the div where you'd normally put what you wanted.

Ex: User enters http://google.com, script detects onchange attribute, uses AJAX to get information about the site.

Here's some simple code:

On your page with the form:
HTML Code:
<script type="text/javascript">
function getURL(url){
var xmlhttp;
if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}
else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200){
    document.getElementById("output").innerHTML=xmlhttp.responseText;
  }
}
xmlhttp.open("GET","urlinfo.php?url="+encodeURIComponent(url),true);
xmlhttp.send();
}
</script>

<!--Form stuff-->
<!--Also make sure the input type is 'url', so it can be parsed by the browser automatically (in newer browsers)-->

<input type="url" name="url" onchange="getURL(this.value)" />

<h3>URL &lt;title&gt; tag content:</h3>
<div id="output">Will be here, this content can be blank</div>
Then on a file called 'urlinfo.php', and this should be all that is on it, nothing else unless you want to get fancy:

PHP Code:
if(isset($_GET['url'])){
    if(
filter_var($url,FILTER_VALIDATE_URL){
        
$html=file_get_contents($url);
        
preg_match("/<title>(.+?)<\/title>/i",$html,$m);
        echo 
$m[1];
        exit;
    }

However this is off the top of my head (aside from the AJAX code, which is from the W3Schools page . The ReGex might now work properly, though. Just play with it and you should be fine

To actually get an image of a webpage, you could always copy the HTML of the remote page, then build it and 'screenshot' it with PHP's GD library. I've never done this before, though.

Hope I could help!

-PG
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 10-16-2011 at 09:21 AM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 10-16-2011, 09:35 AM Re: Scraping page info ( ie image ) from a link entered
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
<pedantic>
onchange is an EVENT not an attribute.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2011, 03:49 AM Re: Scraping page info ( ie image ) from a link entered
Novice Talker

Posts: 10
Name: Umar Bukhari
Location: Pakistan
Trades: 0
you can get all images with jquery easily just get the complete page html and save it into some variable like


Code:
$(document).ready(function() {
    $('body').find('img').each(function() {
        here you go
    });
});
and you can save all images src attribute into an array or as you want and then show them on any where as you want them to be.
angelsdev is offline
Reply With Quote
View Public Profile Visit angelsdev's homepage!
 
Reply     « Reply to Scraping page info ( ie image ) from a link entered
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28581 seconds with 12 queries