Dưới đây là source code cho site như tiêu đề, trong site này mình cũng đã đưa ra vài giải pháp thường gặp (ngoài phần 3 của bài hướng dẫn).
Đó là dùng Regular expression để tìm kiếm trong chuỗi, đây cũng là 1 kĩ thuật rất mạnh dành cho viết auto.
using System; using System.Collections.Generic; using System.ComponentModel.Composition; //using System.Drawing; using System.Linq; using System.Text; using System.IO; using AutoManager.Plugins; using HtmlAgilityPack; using AutoManager.Commons; using System.Text.RegularExpressions; namespace MyFirstPlugin { [Export(typeof(All1PluginScript))] [PluginInfo(PluginName = "Clicks-FX Plugin")] public class ClicksFxPlugin : All1PluginScript { private Queue<string> _linkQueue; public override All1ActionResult Begin(object arg) { Client.GetRequest("member_login"); //NextMethod, ở đây phương thức tiếp theo của ta là SubmitLogin. return new All1NextMethodResult { NextMethod = SubmitLogin }; } private All1ActionResult SubmitLogin(object arg) { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("username", Username); //Username của người dùng nhập dic.Add("password", Password);// Password của người dùng nhập dic.Add("user_type", "Member"); dic.Add("target_page", "member_login"); Client.PostRequest("cgi-bin/gpte30.cgi", dic); Client.GetRequest("member_ptc"); HtmlNodeCollection nodes = Client.ResponseDoc.DocumentNode.SelectNodes("//a[starts-with(@href,'https://clicks-fx.com/cgi-bin/gpte27.cgi?')]"); _linkQueue = new Queue<string>(); if (nodes != null) { foreach (HtmlNode node in nodes) { if (!IsCheatLink(node.ParentNode.InnerText)) { string url = node.Attributes["href"].Value; _linkQueue.Enqueue(url); } } } return new All1NextMethodResult { NextMethod = ProcessAdPage }; } private string GetValueSeparateByEqualSign(string inputStr, string leftSideStr) { Regex regex = new Regex(string.Format("{0}\\s*=\\s*([^,;&]+)", leftSideStr)); Match m = regex.Match(inputStr); if (m.Groups.Count > 1) { return m.Groups[1].Value; } return null; } private All1ActionResult ProcessAdPage(object arg) { if (_linkQueue.Count <= 0) { return new All1NextMethodResult { NextMethod = End }; } string currentAdLink = _linkQueue.Peek(); Client.GetRequest(currentAdLink, "member_ptc"); HtmlNode node = Client.ResponseDoc.DocumentNode.SelectSingleNode("//frame[contains(@src,'clicks-fx.com/gpte/html/click_timer.html')]"); string url1 = node.Attributes["src"].Value; Client.GetRequest(url1, Client.ResponseFullUrl); //Với site clicks-fx, thời gian được chứa trực tiếp trong url1. Ví dụ: //gpte/html/click_timer.html?ad_type=ptc&session=8079876419231180&timer=6&value=0.0002&value_type=cash&logo_url=%2Fclicks-fx.com%2Fgpte%2Fpics%2Flogos.png&logo_width=160px&logo_height=45px //bạn sẽ thấy phần timer=6, chính là thời gian chờ ad, ta phài tìm cách lấy nó. //Lúc này ta sẽ nhờ đến Regular EXpression, nếu bạn ko biết thì có thể search google, nhưng cơ bản là nó sẽ cho phép bạn tìm kiếm chuỗi // một cách dễ dàng nhất. string timerStr = GetValueSeparateByEqualSign(url1, "timer"); int timer = int.Parse(timerStr); return new All1WaitingAdResult { WaitingTime = timer, RemainAds = _linkQueue.Count, NextMethod = (o) => { //ta cũng cần kiếm phần session. string session = GetValueSeparateByEqualSign(url1, "session"); //tạo string cần gửi lên server để xác nhận ad đã xem xong. Random rd = new Random(); string queryStr = "cgi-bin/gpte40.cgi?session=" + session + "&type=ptc&rand=" + rd.Next(100000000); Client.GetRequest(queryStr, Client.ResponseFullUrl); _linkQueue.Dequeue(); return new All1NextMethodResult { NextMethod = ProcessAdPage }; } }; } public override All1ActionResult End(object arg) { Client.GetRequest("member_home"); // Nhìn vào ta thấy html để chứa thông tin tiền như sau: //<p>Points balance: 162<br /> <span style="font-family: GPTEFontBold;">Cash balance: USD 0.0511</span></p> //để lấy được thông tin số tiền ta có 2 cách //1. Dùng Regular Expression //2. Là ta lấy dựa vào thẻ span với style="font-family: GPTEFontBold;" // Ở đây mình dùng cách 2, vì nó có vẻ dễ hơn 😀 HtmlNode textNode = Client.ResponseDoc.DocumentNode.SelectSingleNode("//span[@style='font-family: GPTEFontBold;']"); Amount = ParseHelper.GetAmount(textNode.InnerText); return new All1ActionResult { Message = "Finish" }; } } }
Bạn có thể hướng dẫn mình về cách lấy các loại captcha không, ví dụ như trang ptcsolution.com, mình chưa biết cách lấy captcha của nó ntn.
Thanks bạn.
http://prom247.com/ Mình viết y như mẫu của bạn nhưng nó cứ báo lỗi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using AutoManager.Plugins;
using System.ComponentModel.Composition;
namespace prom247
{
[Export(typeof(All1PluginScript))]
[PluginInfo(PluginName = “Plugin-prom247”)]
public class Prom247Plugin
{
private Queue _linkQueue;
public override All1ActionResult Begin(object arg)
{
Client.GetRequest(“login.html”);
Bitmap bm = Client.GetBitmap(“image2.php?$res”);
return new All1WaitTextCaptResult { Image = bm, NextMethod = SubmitLogin };
}
private All1ActionResult SubmitLogin(object arg)
{
Dictionary dic = new Dictionary();
dic.Add(“logusername”, Username);
dic.Add(“logpassword”, Password);
dic.Add(“code”, CaptchaResultStr);
Client.PostRequest(“login.php”, dic);
if (!Client.ResponseStr.Contains(“prom247.com/exit.html”))
{
return new All1StopingResult { Reason = “LoginFailed” };
}
Client.GetRequest(“sites.php”);
if (Client.ResponseStr.Contains(“specify the number of stars in the picture”))
{
Bitmap captchaBm = Client.GetBitmap(“image.php?Array”);
int result = ColorStarRecognizer.Recognize(captchaBm);
Client.PostRequest(“sites.php”, “code=” + result, Client.ResponseFullUrl);
Client.GetRequest(“sites.php”);
}
HtmlNodeCollection nodes = Client.ResponseDoc.DocumentNode.SelectNodes(“//a[starts-with(@href,’/adview’)]”);
_linkQueue = new Queue();
if (nodes != null)
{
foreach (HtmlNode node in nodes)
if (!IsCheatLink(node.ParentNode.InnerText))
{
string url = node.Attributes[“href”].Value;
_linkQueue.Enqueue(url);
}
}
}
return new All1NextMethodResult { NextMethod = ProcessAdPage };
}
private All1ActionResult ProcessAdPage(object arg)
{
if (_linkQueue.Count
{
Client.GetRequest(“vls.php?view=ok”, Client.ResponseFullUrl);
Bitmap captchaImage = Client.GetBitmap(“image.php?Resource id #5”, Client.ResponseFullUrl);
int result = ColorStarRecognizer.Recognize(captchaImage);
Client.PostRequest(“vls.php?view=ok&ds=clicked”, “code=” + result, Client.ResponseFullUrl);
_linkQueue.Dequeue();
return new All1NextMethodResult { NextMethod = ProcessAdPage };
}
};
}
public override All1ActionResult End(object arg)
{
Client.GetRequest(“profile.html”);
HtmlNode textNode = Client.ResponseDoc.DocumentNode.SelectSingleNode(“//b[text()=’All you have earned:’]”);
Amount = ParseHelper.GetAmount(textNode.ParentNode.ParentNode.InnerText);
return new All1ActionResult { Message = “Finish” };
}
}