Solved

auto login script (pref. PHP)

Posted on 2009-05-08
2
906 Views
Last Modified: 2012-05-06
I need to automate the collection of web data from a real estate site. I would much prefer that this be done in PHP as I can then easily write the data to my own database.

I need to login at (** login info removed **).

On the next page I need to select 'NV' from the drodown and 'clarke' as the county. I then need to input the start date as 05/13/2009 and end date as 05/20/2009 (clearly, all these would be variables which I can change myself).

The sales data should be displayed and I'm pretty sure I can extract this myself. (Bonus points if you have any quick suggestions on rapidly parsing the data).

I've tried using the cUrl libraries without success, but however you want to do it is fine (even suggest a third party provider who can *reliably* do this). The main thing is I need this *fast* (due to failure of third party provider)! As mentioned I would greatly prefer that this be done in PHP.

Many thanks, James.
0
Comment
Question by:smoothisland
2 Comments
 

Accepted Solution

by:
smoothisland earned 0 total points
ID: 24340760
Hi bolscott.

Luckily, in spite of the (non) help from the 'experts', I've managed to figure this out by myself.

The reference to .aspx was because asp servers and .aspx forms have a specific way and requirement of handling POST submissions. The solution is much different from what would have worked when posting to a PHP site.

I appreciate the concern re posting usernames and passwords on the site. There is nothing malicious that anyone could have done with this information and I felt it was necessary to show exactly what I needed to do.

I didn't want the app 'made'. I just needed specific advice re the points I made above. I am aware of terms of use. This app is for an individual client who just wants a mashup from two different sites for which he has paid a subscription.

For the record I am posting the solution. That way you and your "experts" can have a look at it and actually "help" someone who asks about this in the future.


<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.blahblah.com/login.aspx');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "__VIEWSTATE=%2FwEPDwULLTE0NDE2Njc1MzAP...blah blah blah"); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$store1 = curl_exec ($ch);
 
curl_setopt($ch, CURLOPT_URL, 'http://www.blahblah.com/ts.aspx');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTE0ODk5MjAw... blah blah blah");
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$store2 = curl_exec ($ch);
 
echo $store2;  // Do whatever you want...
curl_close ($ch);
?>

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question