I want to implement an 'robot' that could automatically fill forms.
Is there an solution when you can fill data on page for example,form1.html and submit it, wait to next page and submit with data on form2.html,and so on...
In the end it should also 'click' on a button to get a file that the form creates.
I want this 'robot' would use some confidential information, so it cant be done using client side technologies.
I was thinking about PHP - building it as a web site-web service, so you could transfer data to a web address, or a Web Service in .Net.
If it's important,the site I want to fill automatically is runs with ASP.NET.
I kind a new here...Can anyone give some examples or tutorials doing this thing. If exist some technologies that I didn't mention here to realize it I would be glad trying them also.
Forms work by posting data, so instead of making a robot that would type something into every field and click submit, you can just POST the data to the server.
First grab the form fields names, and the action of the form.
Then CURL:
//set POST variables
$url = 'http://domain.com/get-post.php';
$fields = array(
'lname' => urlencode($last_name),
'fname' => urlencode($first_name),
'title' => urlencode($title),
'company' => urlencode($institution),
'age' => urlencode($age),
'email' => urlencode($email),
'phone' => urlencode($phone)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
Snippet from this site.
Use Selenium.
"Selenium automates browsers. That's it. What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well."
See examples here.
Related
I have a link from the via which I can send sms. It works when I put it in the address bar and fill the required get params and press enter. But how can I load it in the middle of controller action (the framework is Yii2 if that matters) ? I tried with mail() but couldn't reach any result.
The link is like below:
http://sms.***********.com/httpApi/Send.aspx?phone=359.........&body=message&username=xxx&password=xxx
Can I make it with plain php or I have to it via javascript ? Thank you in advance!
cURL allows transfer of data across a wide variety of protocols, and is a very powerful system. It's widely used as a way to send data across websites, including things like API interaction and oAuth. cURL is unrestricted in what it can do, from the basic HTTP request, to the more complex FTP upload or interaction with an authentication enclosed HTTPS site. We'll be looking at the simple difference between sending a GET and POST request and dealing with the returned response, as well as highlighting some useful parameters.
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'YOUR API URL',
CURLOPT_USERAGENT => 'cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close().
You should use сURL.
$query = http_build_query([
'phone' => '359.........',
'body' => 'message',
'username' => 'xxx',
'password' => 'xxx'
]);
$c = curl_init();
curl_setopt($c , CURLOPT_URL , 'http://sms.***********.com/httpApi/Send.aspx/?' . $query);
curl_exec($c);
curl_close($c);
Main Idea
I am working on a project and I need to use Google Analytics server side. I do not need to retrieve information, but I need to send information. I could eventually send js script client side, but in this scenario it is not an option.
Most of the following links are really old. 2012~
Retrieving - Not what I need
I have read multiple StackOverflow posts, but they only mention ways to retrieve information.
PHP API for Google Analytics(SO)
Sending - What I need
There is this one post talking about sending information but the GitHub has been deprecated for that library.
Google Analytics PHP API Redirect URI (SO)
Google api php client(GOOGLE)
Question
How do I send information to my Google Analytics account in PHP? Thanks
Be very careful...
Google is able to retrive lot of user informations regarding user-agent, location, ip, campaign, language and so on, using cookies and browser features.
All commands are usually sent using a client-side js script because of that.
If you want to work in server-side you have to handle all the necessary information you need to collect in your statistics before to send the HIT.
For example, if you don't handle UUID properly, google will consider every HIT as "new visitor". If you want to know the geo location of users and your server is in Ireland, every hit made by user will be considered made by an Irish guy. Every ip will be the same of your server, and so on.
I made a custom library using php that consider all these problems.
Basically you can use curl:
function SendGoogleEvent($userid,$category,$action, $label='',$eventvalue=0,$campaign_name='direct',$campaign_source='organic',$campaign_medium='organic'){
$strCookie='';
foreach ($_COOKIE as $key => $value) {
$strCookie.=$key.'='.$value.'; ';
}
$fields_string='';
$fields = array (
'v' => 1,
'tid' => "YOUR GA ID",
'cid' => $userid,
'uip' => $_SERVER['REMOTE_ADDR'],
'dh' => "your site address",
'ul' => 'it-it', // In this case i dont care the user language
't' => 'event',
'ec' => urlencode($category),
'ea' => urlencode($action),
'el' => urlencode($label),
'ev' => $eventvalue
);
if ($campaign_name!='direct') {
$fields["cn"]=$campaign_name;
}
if ($campaign_source!='organic') {
$fields["cs"]=$campaign_source;
}
if ($campaign_medium!='organic') {
$fields["cm"]=$campaign_medium;
}
if (!(substr($_SERVER['HTTP_REFERER'], 0, strlen("your site url")) === "your site url")&&$campaign_name=='direct') {
$fields["dr"]=$_SERVER['HTTP_REFERER'];
}
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, utf8_encode($fields_string));
curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL,"https://ssl.google-analytics.com/collect");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );
curl_exec( $ch );
curl_close($ch);
You send data via the Measurement Protocol. No special library or dev kit is required, you simply append parameters to the GA endpoint and send them via Curl/fopen/sockets/whatever to Google Analytics.
Each calls includes at least the ID of the account you want to send data to, a client id that allows to group interactions into sessions (so it should be unique per visitor, but it must not identify a user personally), an interaction type (pageview, event, timing etc., some interactions types require additional parameters) and the version of the protocol you are using (at the moment there is only one version).
So the most basic example to record a pageview would look like this:
www.google-analytics.com/collect/v=1&tid=UA-XXXXY&cid=555&t=pageview&dp=%2Fmypage
I'm trying to add a new Deal with the Pipedrive API.
To do so I've followed this tutorial: http://support.pipedrive.com/customer/portal/articles/1271064-how-to-send-in-deals-using-a-web-form
But there's something I didn't understand:
"Email API gives your company a special email address you can use to
automate lead generation and adding of new contacts and
organizations."
Where can I get this email address, there's no other mention of it at the tutorial?
Since I'm unable to follow the tutorial I'm trying to add a new deal with cURL, this is the code:
<?php
$deal = array("item_type" => "deal","stage_id" => 1,"title" => "Atendimento Web Site","organization" => "Company","owner" => "johndoe#company.com.br","visible_to" => 2,"person" => array("name" => $nome,"email" => $email,"organization" => $empresa,"phone" => $tel));
$deal_string = json_encode($deal);
$ch = curl_init('https://api.pipedrive.com/v1/deals?api_token=TOKEN');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $deal_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json, charset=UTF-8',
'Content-Length: ' .strlen($deal_string))
);
echo $deal_string;
echo curl_exec($ch);
?>
And this is what I get:
iten sent -> {"item_type":"deal","stage_id":1,"title":"Atendimento","organization":"Company","owner":"owner#mail.com.br","visible_to":2,"person":{"name":"Jo\u00e3o Neto","email":"mail#mail.com.br","organization":"Company 2","phone":"7112345678"}}
return from api -> {"success":false,"error":"Deal title must be given.","data":null,"additional_data":null}
Where's the error?
About the email support it's true that you are mixing two thing, although it was also happened to me the first time. I admit it would seem strange, an API in which you can use emails.
Anyway, I was working on a simple integration between Pipedrive and another platform and I used the full REST API.
I noticed every time you have an error creating a Deal or you make a mistake in the Json (even if title is ok), you always get the same answer "error":"Deal title must be given.". Of courses it won't help you too much.
So, I recommend you to use some tools like RESTClient for Firefox to simplify the problem at the beginning or even Firebug to sniff it from https://developers.pipedrive.com/v1 making use of their tools to understand the request a little bit better. After that, you can do it more complex.
I am putting you a screenshot in which you can see the simplest example. I hope it will be useful for anyone
I'd receive an email from Pipedrive Support with a full anwser.
*Hi,
Thanks for reaching out!
I'm sorry to hear about the trouble!
So you're mixing up two completely separate things. You're sending in the JSON object needed for the Email API into the REST API.
You have 2 options.
You could go full on with the email API. To do this you need to log into your Pipedrive account, navigate to the Settings, Features page and enable the Email API feature. Then click through to the email API page and get the email address you need to send the object to. And then alter your PHP code to send in that object to that email address as a plain text email. No curl or API token needed for that.
You could clean up the data object you're sending in with the REST API. But you need to understand that the REST API works a little different from the Email API. So you can't just send in the person object along with the deal. You would first need to POST in the person with all the details to the persons endpoint and get back the ID. You can then use the person ID in the deals POST.
I hope this helps
Martin Henk | Co-Founder, Head of Customer Support
Pipedrive*
I have a PHP/JavaScript site (offline). I am using http://crum.bs/ for shortening URLs.
Here, there are 2 types of APIs provided by crum.bs:
Simple Shorten, and
Advanced Shorten
I am currently using the simple shorten API. The base URL to make a GET request is http://crum.bs/api.php?function=simpleshorten&url=[insert url here].
Now, I am planning to change it to the advanced API which requires POST.
I can't find the Base for this anywhere on that page (Or in Google).
The API Reference Page is http://blog.crum.bs/?p=12. Does anybody know what it is?
From what I see you would submit your POST request to the same path
http://crum.bs/api.php
You just need to pass the variables in the request (which technically would look the same as the Simple version, just a different HTTP verb is used)
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "http://crum.bs/api.php",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array(
'url' => 'http://www.some-really-long-url.com/with/a/lot/of/text/etc.html',
'desc' => 'some other data',
),
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
The $result var will contain the JSON response from crum.bs service
So I wanted to do the following: a php script should upload a picture with a title to a facebook page.
I then googled around a bit and found this: Simple example to post to a Facebook fan page via PHP?
Everything works fine, but sadly the result is not what I wanted. Instead of a "full" image, I only get a cripple: http://i.imgur.com/2qINX.jpg
Can you help me out? The script will need offline access and I've already an app. I will only need it to upload pictures along with a title, nothing more.
Before this I was uploading pictures through the Email provided by Facebook for mobile users, but that's not satisfying anymore. I mean, it can't be that hard. But if I don't figure this out, I will rent a virtual windows server and run a script that loggs into Facebook and posts the image.
You can upload a picture to your page using-
$image['file'] = PATH_TO_PICTURE;
$args = array( 'access_token' => PAGE_ACCESS_TOKEN, 'message' => '','no_story' => 0);
$args['image'] = '#' . $image['file'];
$target_url = "https://graph.facebook.com/ALBUM_ID/photos";
$ch = curl_init();
curl_setopt ($ch,CURLOPT_URL,$target_url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_exec($ch);
curl_close ($ch);
PAGE_ACCESS_TOKEN
Get the list of pages/apps-
$facebook->api("/USER_ID/accounts");
Get the pages' access token-
$facebook->api("/PAGE_ID?fields=access_token");
This will load up a picture to a specific gallery:
$newphotodata = array(
'access_token' => $fanPageAccessToken,
'message' => $message,
'no_story' => 1,
'aid' => $albumId,
'image' => '#' . $picturePath);
$uploadedphoto = $facebook->api('/' . $albumId . '/photos/', 'post', $newphotodata);
You need the following permissions too though:
read_stream, manage_pages, publish_stream, photo_upload, user_photos, user_photo_video_tags
I'm not sure whether the user_photos and user_photo_video_tags are actually needed, so try without if you get it working with.
Also, you need the following line before you make the call:
$facebook->setFileUploadSupport(true);
You basically need to do two things first though.
First you need to query the API to get an access token for whatever page you want to post to.
You do this by the following api call:
$fanpages = $facebook->api('me/accounts?access_token='.$accessToken);
You then loop through $fanpages['data'], to find the page you want:
$fanPageAccessToken = $fanPage['access_token']
You then make the call given above, using the appropriate album id.
Now, if you don't know what album id you require, take a look at the following:
$fan_albums = $facebook->api($fanPageId.'/albums/');
This will show all the albums. The key fields at the moment will be ['id'] and ['name'].
Once you have made the post, there will be no evidence of it. So what you should then do is post a link to the photo on the links feed. If you need help with that then ask and I will provide the info.
Alternatively, check out these two articles I wrote a while ago, which cover the same thing.
http://facebookanswers.co.uk/?p=262
http://facebookanswers.co.uk/?p=322