一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語言 - JAVA教程 - Java實(shí)現(xiàn)仿淘寶滑動驗(yàn)證碼研究代碼詳解

Java實(shí)現(xiàn)仿淘寶滑動驗(yàn)證碼研究代碼詳解

2020-05-22 10:25Sam Xiao JAVA教程

這篇文章主要介紹了Java實(shí)現(xiàn)仿淘寶滑動驗(yàn)證碼研究代碼詳解的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

通過下面一張圖看下要實(shí)現(xiàn)的功能,具體詳情如下所示:

Java實(shí)現(xiàn)仿淘寶滑動驗(yàn)證碼研究代碼詳解

現(xiàn)在我就來介紹些軟件的其它功能。希望大家有所受益。

模擬人為搜索商品

在刷單的時(shí)候,不能直接拿到一個(gè)商品網(wǎng)址就進(jìn)入購買頁面吧,得模擬人為搜索。

在這一個(gè)過程中有兩個(gè)難點(diǎn):

1)商品列表的異步加載 ; 2)翻頁并且截圖;

在園子里,我就不在關(guān)公面前耍大刀了。

直接上關(guān)鍵代碼:

i:搜索商品,并且翻頁

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
public bool? SearchProduct(TaskDetailModel taskDetailData)
{
bool? result = null;
bool isIndex = true;
bool isList = true;
WebBrowserTask.Instance.SetProperties();
WebBrowserTask.Instance.ClearDocumentCompleted();
WebBrowserTask.Instance.DocumentCompleted += (wbSenderSearch, wbESearch) =>
{
System.Windows.Forms.WebBrowser currentWB = wbSenderSearch as System.Windows.Forms.WebBrowser;
System.Windows.Forms.HtmlDocument currentDoc = currentWB.Document;
mshtml.HTMLDocument currentDom = currentDoc.DomDocument as mshtml.HTMLDocument;
String wbUrl = wbESearch.Url.ToString();
if (currentWB.ReadyState == System.Windows.Forms.WebBrowserReadyState.Complete)
{
#region 首頁搜索
if (wbUrl.Contains("www.taobao.com"))
{
if (isIndex == true)
{
isIndex = false;
taskDetailData.DetailRemark = String.Format(@"輸入關(guān)鍵字""{0}""搜索商品……", taskDetailData.TaskName);
Func<bool> func = () =>
{
bool asynctag = false;
System.Threading.Thread.Sleep(5000);
asynctag = true;
return asynctag;
};
func.BeginInvoke((ar) =>
{
bool asyncresult = func.EndInvoke(ar);
if (asyncresult)
{
System.Windows.Forms.HtmlElement heee = currentDoc.GetElementById("J_SearchTab");
String classname = heee.GetAttribute("classname");
System.Windows.Forms.HtmlElement hitem = heee.Children[0];
System.Windows.Forms.HtmlElementCollection heclis = hitem.Children;
System.Windows.Forms.HtmlElement li1 = heclis[0];
System.Windows.Forms.HtmlElement li2 = heclis[1];
System.Windows.Forms.HtmlElement li3 = heclis[2];
foreach (System.Windows.Forms.HtmlElement li in heclis)
{
String liclass = li.GetAttribute("classname");
if (liclass.Contains("selected"))
{
System.Windows.Forms.HtmlElement q = currentDoc.GetElementById("q");
System.Windows.Forms.HtmlElement btnsearch = currentDoc.GetElementById("J_TSearchForm").Children[0].Children[0];
if (q != null && btnsearch != null)
{
q.Focus();
q.SetAttribute("value", taskDetailData.TaskName);
btnsearch.Focus();
string savePath = Path.Combine(UserData.WorkBenchDirectory, taskDetailData.TaskDetailCode, String.Format("搜索提交.jpg", ""));
CaptureImage.CaptureWebPageArea(currentDom, savePath);
btnsearch.InvokeMember("click");
}
}
}
}
},
null);
}
}
#endregion 首頁搜索
#region 商品列表
if (wbUrl.Contains("s.taobao.com"))
{
if (isList == true)
{
isList = false;
Func<bool> func = () =>
{
bool asynctag = false;
asynctag = true;
return asynctag;
};
func.BeginInvoke((ar) =>
{
bool asyncresult = func.EndInvoke(ar);
if (asyncresult)
{
//解析每頁商品
String clickProductURL = TurningAndParsePage(currentDoc, taskDetailData);
result = true;
}
},
null);
}
}
#endregion 商品列表
}
}; //DocumentCompleted結(jié)束
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() =>
{
WebBrowserTask.Instance.Navigate("https://www.taobao.com/");
}));
for (int i = 0; i < 120; i++)
{
System.Threading.Thread.Sleep(1000);
if (result != null)
{
break;
}
}
return result;
}

ii:因?yàn)槊總€(gè)頁面都是異常加載的,選擇適當(dāng)?shù)臅r(shí)機(jī)對網(wǎng)頁進(jìn)行截圖
截取整個(gè)網(wǎng)頁:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
因?yàn)榘丝丶绻诹司€程里調(diào)用,必須用Invoke方法
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() =>
{
//htmlDoc.Window.ScrollTo(new System.Drawing.Point(5000, htmlDoc.Body.ScrollRectangle.Height));
string savePath = string.Format(@"D:\{0}.jpg", Guid.NewGuid().ToString());
CaptureImage.CaptureWebPage(webBrowserTask, savePath);
}), System.Windows.Threading.DispatcherPriority.Background);
*/
/// <summary>
/// 截取整個(gè)網(wǎng)頁
/// </summary>
/// <param name="web"></param>
/// <param name="savePath"></param>
public static void CaptureWebPage(System.Windows.Forms.WebBrowser web, String savePath)
{
Rectangle body = web.Document.Body.ScrollRectangle;
Rectangle docRectangle = new Rectangle()
{
Location = new Point(0, 0),
Size = new Size(body.Width, body.Height)
};
web.Dock = DockStyle.None;
web.Width = docRectangle.Width;
web.Height = docRectangle.Height;
Rectangle imgRectangle = docRectangle;
using (Bitmap bitmap = new Bitmap(imgRectangle.Width, imgRectangle.Height))
{
IViewObject ivo = web.Document.DomDocument as IViewObject;
using (Graphics g = Graphics.FromImage(bitmap))
{
IntPtr hdc = g.GetHdc();
ivo.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, hdc, ref imgRectangle, ref docRectangle, IntPtr.Zero, 0);
g.ReleaseHdc(hdc);
}
bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
}
}

截取網(wǎng)頁的某個(gè)區(qū)域:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/// <summary>
/// 截取網(wǎng)頁的一部份
/// </summary>
/// <param name="htmlDom"></param>
/// <param name="savePath"></param>
public static void CaptureWebPageArea(mshtml.HTMLDocument htmlDom, String savePath)
{
String saveDir = System.IO.Path.GetDirectoryName(savePath);
if (!System.IO.Directory.Exists(saveDir))
{
System.IO.Directory.CreateDirectory(saveDir);
}
Rectangle docRectangle = new Rectangle()
{
Location = new Point(0, 0),
//Size = new Size(htmlDom.body.offsetWidth, htmlDom.body.offsetHeight)
Size = new Size((int)System.Windows.SystemParameters.PrimaryScreenWidth, (int)System.Windows.SystemParameters.PrimaryScreenHeight)
};
Rectangle imgRectangle = docRectangle;
using (Bitmap bitmap = new Bitmap(imgRectangle.Width, imgRectangle.Height))
{
IViewObject ivo = htmlDom as IViewObject;
using (Graphics g = Graphics.FromImage(bitmap))
{
IntPtr hdc = g.GetHdc();
ivo.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, hdc, ref imgRectangle, ref docRectangle, IntPtr.Zero, 0);
g.ReleaseHdc(hdc);
}
bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
}
}

在這代碼里有很多有趣的片段。有心的朋友會發(fā)現(xiàn)。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩美一区二区三区 | 成年人在线免费观看视频网站 | 成人午夜在线视频 | 丝袜性爱| 瘦老汉gay| 私人影院在线免费观看 | 日噜噜 | 日韩欧美一区二区三区免费看 | 精品高潮呻吟99AV无码视频 | 操比图片| 亚洲福利在线观看 | 91制片厂果冻星空传媒3xg | 成人在线一区二区 | 久久国产精品免费网站 | 青青网在线视频 | 男女乱淫真视频播放网站 | 男人插女人软件 | 国产最新进精品视频 | 好男人社区www影院在线观看 | 日本精品www色 | 日韩亚洲欧美综合一区二区三区 | 日韩欧美亚洲每日更新网 | 亚洲精品动漫免费二区 | 青草香蕉精品视频在线观看 | 色综合久久综合网欧美综合网 | 性姿势女人嗷嗷叫图片 | 男女视频在线观看网站 | 国产精品va在线观看手机版 | 青青青草国产线观 | 成人高辣h视频一区二区在线观看 | 亚洲国产欧美在线人成aaaa20 | 天天舔天天操天天干 | 男女刺激高清视频在线观看 | 18未年禁止免费观看 | 777奇米影视一区二区三区 | 北岛玲亚洲一区在线观看 | 亚州笫一色惰网站 | 亚洲va久久久噜噜噜久久狠狠 | 亚洲欧美国产在线 | 天堂avav| 希望影院高清免费观看视频 |