Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-18-2010, 07:36 AM
|
#1
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Rep:
|
check if a website file has changed
I have a site that I login to to check updates. It does not have RSS because users need to authenticate themselves before getting access to the page.
Is there a way to write a script that can login to the page and check whether the HTML has changed and then send me an email?
|
|
|
01-18-2010, 08:40 AM
|
#2
|
Member
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208
Rep:
|
You could maybe script wget to do this? If wget asks for a log and password for the website, then you could automate this using expect. Another way to do this is to use the urllib or urllib2 in python. Depending on how you have to log into the page, these should do what you are looking for.
|
|
|
01-18-2010, 08:55 AM
|
#3
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Original Poster
Rep:
|
Quote:
Originally Posted by nuwen52
You could maybe script wget to do this? If wget asks for a log and password for the website, then you could automate this using expect. Another way to do this is to use the urllib or urllib2 in python. Depending on how you have to log into the page, these should do what you are looking for.
|
I cannot get wget to successfully login to the page. I try to submit the details by POST to a login form but it doesn't pick up the correct page afterwards, just the standard page when not logged in.
I picked up the form name from the source on this page, not sure if it's the correct one or not: https://www.inthemoneystocks.com/pro...watch_list.php
Last edited by qwertyjjj; 01-18-2010 at 09:30 AM.
|
|
|
01-18-2010, 01:24 PM
|
#4
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Original Poster
Rep:
|
any thoughts on the login part?
|
|
|
01-18-2010, 04:17 PM
|
#5
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Original Poster
Rep:
|
After the initial request, it is rerouted through to login again :
Code:
[root@server ~]# wget --save-cookies cookies.txt --keep-session-cookies --post-data 'username=MYUSERN¤tpassword=MYPASS' http://www.inthemoneystocks.com/login.php
--2010-01-18 22:15:12-- http://www.inthemoneystocks.com/login.php
Resolving www.inthemoneystocks.com... 72.29.80.60
Connecting to www.inthemoneystocks.com|72.29.80.60|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16397 (16K) [text/html]
Saving to: `login.php.1'
100%[=======================================================================================================================================>] 16,397 62.9K/s in 0.3s
2010-01-18 22:15:13 (62.9 KB/s) - `login.php.1' saved [16397/16397]
[root@server ~]# wget --load-cookies cookies.txt -p https://www.inthemoneystocks.com/pro_trader_watch_list_prem.php --2010-01-18 22:15:45-- https://www.inthemoneystocks.com/pro_trader_watch_list_prem.php
Resolving www.inthemoneystocks.com... 72.29.80.60
Connecting to www.inthemoneystocks.com|72.29.80.60|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://www.inthemoneystocks.com/login.php [following]
--2010-01-18 22:15:45-- https://www.inthemoneystocks.com/login.php
Connecting to www.inthemoneystocks.com|72.29.80.60|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16254 (16K) [text/html]
Saving to: `www.inthemoneystocks.com/login.php'
100%[=======================================================================================================================================>] 16,254 68.3K/s in 0.2s
2010-01-18 22:15:46 (68.3 KB/s) - `www.inthemoneystocks.com/login.php' saved [16254/16254]
Loading robots.txt; please ignore errors.
--2010-01-18 22:15:46-- https://www.inthemoneystocks.com/robots.txt
Reusing existing connection to www.inthemoneystocks.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 191 [text/plain]
Saving to: `www.inthemoneystocks.com/robots.txt'
100%[=======================================================================================================================================>] 191 --.-K/s in 0s
2010-01-18 22:15:46 (6.77 MB/s) - `www.inthemoneystocks.com/robots.txt' saved [191/191]
--2010-01-18 22:15:46-- https://www.inthemoneystocks.com/main.css
Reusing existing connection to www.inthemoneystocks.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 19172 (19K) [text/css]
Saving to: `www.inthemoneystocks.com/main.css'
100%[=======================================================================================================================================>] 19,172 --.-K/s in 0.1s
2010-01-18 22:15:47 (159 KB/s) - `www.inthemoneystocks.com/main.css' saved [19172/19172]
--2010-01-18 22:15:47-- https://www.inthemoneystocks.com/js/mootools1.11.js
Reusing existing connection to www.inthemoneystocks.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 43715 (43K) [application/javascript]
Saving to: `www.inthemoneystocks.com/js/mootools1.11.js'
100%[=======================================================================================================================================>] 43,715 183K/s in 0.2s
2010-01-18 22:15:47 (183 KB/s) - `www.inthemoneystocks.com/js/mootools1.11.js' saved [43715/43715]
--2010-01-18 22:15:47-- https://www.inthemoneystocks.com/js/fValidator.js
Reusing existing connection to www.inthemoneystocks.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 8966 (8.8K) [application/javascript]
Saving to: `www.inthemoneystocks.com/js/fValidator.js'
100%[=======================================================================================================================================>] 8,966 --.-K/s in 0.001s
2010-01-18 22:15:47 (10.4 MB/s) - `www.inthemoneystocks.com/js/fValidator.js' saved [8966/8966]
--2010-01-18 22:15:47-- https://www.inthemoneystocks.com/js/purchaseform.js
Reusing existing connection to www.inthemoneystocks.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 7248 (7.1K) [application/javascript]
Saving to: `www.inthemoneystocks.com/js/purchaseform.js'
100%[=======================================================================================================================================>] 7,248 --.-K/s in 0.001s
2010-01-18 22:15:47 (8.26 MB/s) - `www.inthemoneystocks.com/js/purchaseform.js' saved [7248/7248]
--2010-01-18 22:15:47-- https://www.inthemoneystocks.com/ticker.swf
Reusing existing connection to www.inthemoneystocks.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 43872 (43K) [application/x-shockwave-flash]
Saving to: `www.inthemoneystocks.com/ticker.swf'
100%[=======================================================================================================================================>] 43,872 --.-K/s in 0.1s
2010-01-18 22:15:47 (361 KB/s) - `www.inthemoneystocks.com/ticker.swf' saved [43872/43872]
FINISHED --2010-01-18 22:15:47--
Downloaded: 7 files, 136K in 0.7s (193 KB/s)
[root@server~]#
Last edited by qwertyjjj; 01-18-2010 at 04:18 PM.
|
|
|
01-18-2010, 04:57 PM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,397
|
|
|
|
01-18-2010, 06:07 PM
|
#7
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Original Poster
Rep:
|
Quote:
Originally Posted by chrism01
|
I just thought wget would do it simply.
Could I use PHP as well? I'm more mailiar with that than perl.
What lib do I need for PHP?
|
|
|
01-18-2010, 06:29 PM
|
#8
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Original Poster
Rep:
|
Here is my current curl file but it doesn't seem to download the file:
Code:
#! /usr/bin/php
<?php
// INIT CURL
$ch = curl_init();
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL,
'https://www.inthemoneystocks.com/login.php');
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS,
'username=xxxxx¤tpassword=xxxxx');
// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);
// SET FILE TO DOWNLOAD
curl_setopt($ch, CURLOPT_URL,
'https://www.inthemoneystocks.com/pro_trader_watch_list_prem.php');
// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
$content = curl_exec ($ch);
// CLOSE CURL
curl_close ($ch);
?>
I guess I need to write $content to a file? How do I do that?
Last edited by qwertyjjj; 01-18-2010 at 06:33 PM.
|
|
|
01-18-2010, 08:17 PM
|
#9
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Original Poster
Rep:
|
I've got it into a file but I am noe using file_get_contents to check the new file every 10mins and if it changes then I email it to myself.
Unfortunately, curl or something is changing the file size by a few bytes even if nothing has changed.
Any ideas?
|
|
|
01-19-2010, 07:39 AM
|
#10
|
Member
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208
Rep:
|
Is there a date or perhaps a number of hits counter on the page? Curl should just get contents unmodified, so it's probably the page itself that is changing. I would do a diff on two versions of the page and see what changed. Then you can remove those sections from your checks. Just a thought.
|
|
|
01-19-2010, 08:08 AM
|
#11
|
Senior Member
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013
Original Poster
Rep:
|
Quote:
Originally Posted by nuwen52
Is there a date or perhaps a number of hits counter on the page? Curl should just get contents unmodified, so it's probably the page itself that is changing. I would do a diff on two versions of the page and see what changed. Then you can remove those sections from your checks. Just a thought.
|
Any ideas on how to do a diff in PHP?
|
|
|
01-19-2010, 08:58 AM
|
#12
|
Member
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208
Rep:
|
Well, what I meant was do a diff manually just to see what's different. If what's different is minor, then you can program your php script to ignore those minor types of changes. Like, if the line that's different looks like "DATE: Thu Feb 27 2010", then you can tell the script to ignore that line when determining if the file changed. But, other than that...
Code:
exec("diff <file1> <file2> > /tmp/difftmp.txt");
diff_file=fopen("/tmp/difftmp.txt", "r");
and interpret the file. I don't know of a PHP library for diff.
Last edited by nuwen52; 01-19-2010 at 08:59 AM.
|
|
|
All times are GMT -5. The time now is 07:52 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|