Advertising
PHP or Javascript?
PHP or Javascript?
I'll looking to make a something that will take a webpage and find links in it and don't know what to use, so I thought I'd ask here. Is that even possible with PHP or Javascript? What do you guys recommend?
You probably didn't know that you don't know that you don't know what you don't know.
I know I'm crazy, the real question is are you?
Life is nothing but discrimination, likes, dislikes, any choice made ... all a product of discrimination.
I know I'm crazy, the real question is are you?
Life is nothing but discrimination, likes, dislikes, any choice made ... all a product of discrimination.
Re: PHP or Javascript?
I think it would be hard with both.
Because Javascript is a client-side language and PHP a server-side language.
That means PHP runs as/on the server and Javascript on the PC of the client,
interpreted by the browser (as example Firefox).
I do not know Javascript nor PHP, so I am not sure.
I suppose a scripting language would be the best choice.
Because Javascript is a client-side language and PHP a server-side language.
That means PHP runs as/on the server and Javascript on the PC of the client,
interpreted by the browser (as example Firefox).
I do not know Javascript nor PHP, so I am not sure.
I suppose a scripting language would be the best choice.
Advertising
Re: PHP or Javascript?
Perl FTW. Does wonders with file parsing. Wanna me show you how to do a web page parser?ohrores wrote:I suppose a scripting language would be the best choice.
Also a correction if you don't mind:
Yes you're right, but you can anyway get a PHP and/or JS interpreter and run code on your own PCohrores wrote:Because Javascript is a client-side language and PHP a server-side language.
That means PHP runs as/on the server and Javascript on the PC of the client,
EDIT: Just for fun, I made it. It was a nice exercise. Probably needs a bit of polishing but it does extract the links from web pages
Code: Select all
#!/usr/bin/perl
# Online HTML Parser by m0skit0
# 12/01/2012
# Usage: script.pl <URL to parse>
use strict;
use HTML::Parser;
use LWP::UserAgent;
use constant HTTP_AGENT => "DarthPerl/3.0";
use constant HTML_LINK_TAG => "a";
# Invoked each time a starting tag is found
sub start
{
my ($tagname, $attr) = @_;
if ($tagname eq HTML_LINK_TAG)
{
print ("$attr->{href}\n");
}
}
########
# MAIN #
########
# Create a UserAgent (HTTP client)
my $ua = LWP::UserAgent->new();
$ua->agent(HTTP_AGENT);
# Create an HTTP request
my $req = HTTP::Request->new(GET => $ARGV[0]);
# Request the page
my $res = $ua->request($req);
# If successful
if ($res->is_success)
{
# Create an HTML parser
my $parser = HTML::Parser->new
(
api_version => 3,
start_h => [\&start, "tagname, attr"],
);
# Parse web page
$parser->parse($res->content);
}
# Request failed
else
{
print "$res->status_line\n";
}
# Bye bye and have funI wanna lots of mov al,0xb

"just not into this RA stuffz"

"just not into this RA stuffz"
Re: PHP or Javascript?
thanks for the example
i'll guess i'll try and learn perl then. hoping the make something to help me with my webcomic addiction (have over 100 bookmarked that I check each day
)
You probably didn't know that you don't know that you don't know what you don't know.
I know I'm crazy, the real question is are you?
Life is nothing but discrimination, likes, dislikes, any choice made ... all a product of discrimination.
I know I'm crazy, the real question is are you?
Life is nothing but discrimination, likes, dislikes, any choice made ... all a product of discrimination.



