最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【代码分享】C#代码:AuthorityCommentFinder – 模拟(chasethefootprint和DropMyLink添加footprint后去)google搜索

CodeShare crifan 107445浏览

【背景】

之前做的AuthorityCommentFinder,模拟了:

http://dropMyLink.com

http://chasethefootprint.com

其实就是:

添加了对应的footprint后,去google搜索。

【AuthorityCommentFinder代码分享】

1.截图:

AuthorityCommentFinder dropmylink

AuthorityCommentFinder chasethefootprint

2.完整项目代码下载:

AuthorityCommentFinder_2013-07-16.7z

 

3.更多说明:

(1)关于google搜索,已整理成库,需要的去看:

https://code.google.com/p/crifanlib/source/browse/trunk/csharp/crifanLibGoogle.cs

4.代码分享:

(1)frmAuthorityCommentFinder.cs

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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
/*
 * [File]
 * frmAuthorityCommentFinder.cs
 *
 * [Function]
 * 1. emulate dropMyLink.com to do google search
 * 2. emulate chasethefootprint.com to do google search
 *
 * [Author]
 * Crifan Li
 *
 * [Date]
 * 2013-07-16
 *
 * [Contact]
 */
   
#define DEBUG
//later calculate alexa rank and page rank
#define LATE_CALC_RANK
   
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
   
using System.Web;
using System.Net;
   
using HtmlAgilityPack;
using System.IO;
   
namespace AuthorityCommentFinder
{
    public partial class frmAuthorityCommentFinder : Form
    {
        public crifanLib crifanLib;
        public crifanLibGoogle google;
   
        //static int titleColumnIdx = 0;
        static int urlColumnIdx = 1;
        static int pageRankColumnIdx = 2;
        static int alexaRankColumnIdx = 3;
   
        public DataGridViewButtonColumn visitUrlColumn = null;
        public static int visitUrlColumnIdx = 4;
   
        //need continue search or not
        bool needContinueSearch = true;
   
        public const int invalidRankValue = -1;
   
        enum search_status
        {
            SEARCH_STATUS_STOPPED,
            SEARCH_STATUS_SEARCHING,
            //SEARCH_STATUS_PAUSED
        };
        search_status curSearchStatus = search_status.SEARCH_STATUS_STOPPED;
        //search_status curSearchStatus_footprint = search_status.SEARCH_STATUS_STOPPED;
           
        public frmAuthorityCommentFinder()
        {
            //!!! for load embedded dll: (1) register resovle handler
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
   
            InitializeComponent();
   
            crifanLib = new crifanLib();
            google = new crifanLibGoogle();
   
            visitUrlColumn = new DataGridViewButtonColumn();
        }
   
        //!!! for load embedded dll: (2) implement this handler
        System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            string dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", "");
   
            dllName = dllName.Replace(".", "_");
   
            if (dllName.EndsWith("_resources")) return null;
   
            System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
   
            byte[] bytes = (byte[])rm.GetObject(dllName);
   
            return System.Reflection.Assembly.Load(bytes);
        }
   
        void initSearchResultGridView()
        {
            dgvSearchResult.ColumnCount = 4;
   
            dgvSearchResult.RowHeadersWidth = 60;
            dgvSearchResult.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvSearchResult.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
   
            //dgvSearchResult.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            dgvSearchResult.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvSearchResult.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
   
            //(1)title
            //dgvSearchedAlerts.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSearchResult.Columns[0].HeaderText = "Title";
            dgvSearchResult.Columns[0].Width = 400;
            //(2)Url
            dgvSearchResult.Columns[1].HeaderText = "Url";
            dgvSearchResult.Columns[1].Width = 400;
   
            //(3)page rank of the domain
            //http://pagerank.webmasterhome.cn/
            //http://pr.chinaz.com/
            dgvSearchResult.Columns[2].HeaderText = "Page Rank";
            dgvSearchResult.Columns[2].Width = 100;
   
            //(4)alexa rank of the domain
            //http://moonsy.com/alexa_rank/
            //http://alexa.chinaz.com/
            dgvSearchResult.Columns[3].HeaderText = "Alexa Rank";
            dgvSearchResult.Columns[3].Width = 100;
   
            //(5)vist the page button
            // Add a button column
            visitUrlColumn.HeaderText = "View Page";
            //visitUrlColumn.Name = "Goto Url";
            visitUrlColumn.Text = "Visit Url";
            //visitUrlColumn.UseColumnTextForButtonValue = true;
            //visitUrlColumn.Width = 60;
            dgvSearchResult.Columns.Add(visitUrlColumn);
            visitUrlColumn.Width = 80;
        }
   
        private struct footprintPair
        {
            public string ShowString { get; set; } // for show
            public string EncodedAppend { get; set; } //for real appendded footprint
            public bool BAppendKeywordToEnd; //normall apped keyword to previous of footprint, some special apped to end
        }
   
        private struct keyValueList
        {
            public string Key{get;set;} // key
            //public List<string> ValueStrList{get;set;} // the string value list for the key
            public List<footprintPair> ValuePairList { get; set; } // the string value list for the key
        }
   
        List<keyValueList> gFootprintTypeSelList; // footprint type
   
   
        private void initFootprintTypeAndFootprintString()
        {
            gFootprintTypeSelList = new List<keyValueList>();
               
            //init
            footprintPair footprintPair = new footprintPair();
   
            //1. option1: Guest Blogging
            keyValueList keyValueListGuestBlogging = new keyValueList();
            keyValueListGuestBlogging.Key = "Guest Blogging";
            //keyValueListGuestBlogging.ValueStrList = new List<string>();
            keyValueListGuestBlogging.ValuePairList = new List<footprintPair>();
               
            footprintPair.ShowString = "Guest Blogging";
            //"guest blogger" OR "guest post" OR "guest article" OR "Add Guest Post" OR "Submit Guest Post" OR "Submit a Guest Article" OR "Guest Post Guidelines"
            footprintPair.EncodedAppend = "%22guest%20blogger%22%20OR%20%22guest%20post%22%20OR%20%22guest%20article%22%20OR%20%22Add%20Guest%20Post%22%20OR%20%22Submit%20Guest%20Post%22%20OR%20%22Submit%20a%20Guest%20Article%22%20OR%20%22Guest%20Post%20Guidelines%22";
            keyValueListGuestBlogging.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Contribute";
            //"become a contributor" OR "contribute to this site" OR "Add Content"
            footprintPair.EncodedAppend = "%22become%20a%20contributor%22%20OR%20%22contribute%20to%20this%20site%22%20OR%20%22Add%20Content%22";
            keyValueListGuestBlogging.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Write for us";
            //""write for us" OR "write for me"" OR "submit your writing" OR "submit article"
            footprintPair.EncodedAppend = "%22%22write%20for%20us%22%20OR%20%22write%20for%20me%22%22%20OR%20%22submit%20your%20writing%22%20OR%20%22submit%20article%22";
            keyValueListGuestBlogging.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Guest Category";
            //"inurl:category/guest"
            footprintPair.EncodedAppend = "%22inurl%3Acategory/guest%22";
            keyValueListGuestBlogging.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Submit Content";
            //"submit content" OR "post content"
            footprintPair.EncodedAppend = "%22submit%20content%22%20OR%20%22post%20content%22";
            keyValueListGuestBlogging.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListGuestBlogging);
   
            //2. option2: Blog Commenting
            keyValueList keyValueListBlogCommenting = new keyValueList();
            keyValueListBlogCommenting.Key = "Blog Commenting";
            keyValueListBlogCommenting.ValuePairList = new List<footprintPair>();
   
            footprintPair.ShowString = "KeywordLuv Blogs";
            //"Enter YourName@YourKeywords"
            footprintPair.EncodedAppend = "%22Enter%20YourName@YourKeywords%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Joomla JComments Plugin";
            //"Powered by JComments"
            footprintPair.EncodedAppend = "%22Powered%20by%20JComments%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Yootheme Zoo Blog App";
            //"inurl:"option=com_zoo"
            footprintPair.EncodedAppend = "%22inurl%3A%22option%3Dcom_zoo%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "CommentLuv Premium Blogs";
            //"This blog uses premium CommentLuv" -"The version of CommentLuv on this site is no longer supported."
            footprintPair.EncodedAppend = "%22This%20blog%20uses%20premium%20CommentLuv%22%20-%22The%20version%20of%20CommentLuv%20on%20this%20site%20is%20no%20longer%20supported.%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Anchor Text In Comment Blogs";
            //"Allowed HTML tags:"
            footprintPair.EncodedAppend = "%22Allowed%20HTML%20tags%3A%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Do Follow Comment Blogs";
            //"Notify me of follow-up comments?" "Submit the word you see below"
            footprintPair.EncodedAppend = "%22Notify%20me%20of%20follow-up%20comments%3F%22+%22Submit%20the%20word%20you%20see%20below%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Create your own .GOV WordPress site";
            //inurl:.gov inurl:wp-signup.php
            footprintPair.EncodedAppend = "inurl%3A.gov%20inurl%3Awp-signup.php";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Create your own .EDU WordPress site";
            //inurl:.edu inurl:wp-signup.php
            footprintPair.EncodedAppend = "inurl%3A.edu%20inurl%3Awp-signup.php";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Find .edu Blogs";
            //site:.edu inurl:blog "post a comment" -"you must be logged in"
            footprintPair.EncodedAppend = "site%3A.edu%20inurl%3Ablog%20%22post%20a%20comment%22%20-%22you%20must%20be%20logged%20in%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Find .gov Blogs";
            //site:.gov inurl:blog "post a comment" -"you must be logged in"
            footprintPair.EncodedAppend = "site%3A.gov%20inurl%3Ablog%20%22post%20a%20comment%22%20-%22you%20must%20be%20logged%20in%22";
            keyValueListBlogCommenting.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListBlogCommenting);
   
            //3. option3: Message Boards and Forums
            keyValueList keyValueListMessageBoardsAndForums = new keyValueList();
            keyValueListMessageBoardsAndForums.Key = "Message Boards and Forums";
            keyValueListMessageBoardsAndForums.ValuePairList = new List<footprintPair>();
                           
            footprintPair.ShowString = "PHPbb";
            //"Powered by PHPbb"
            footprintPair.EncodedAppend = "%22Powered%20by%20PHPbb%22";
            keyValueListMessageBoardsAndForums.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "vBulletin";
            //"Powered by vBulletin"
            footprintPair.EncodedAppend = "%22Powered%20by%20vBulletin%22";
            keyValueListMessageBoardsAndForums.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "SMF";
            //"Powered by SMF"
            footprintPair.EncodedAppend = "%22Powered%20by%20SMF%22";
            keyValueListMessageBoardsAndForums.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Simple Machines";
            //"powered by Simple Machines"
            footprintPair.EncodedAppend = "%22powered%20by%20Simple%20Machines%22";
            keyValueListMessageBoardsAndForums.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "punBB";
            //"powered by punBB"
            footprintPair.EncodedAppend = "%22powered%20by%20punBB%22";
            keyValueListMessageBoardsAndForums.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Expression Engine";
            //"powered by expressionengine"
            footprintPair.EncodedAppend = "%22powered%20by%20expressionengine%22";
            keyValueListMessageBoardsAndForums.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Blog Engine";
            //"Powered by BlogEngine.NET" inurl:blog "post a comment" -"comments closed"
            footprintPair.EncodedAppend = "%22Powered%20by%20BlogEngine.NET%22%20inurl%3Ablog%20%22post%20a%20comment%22%20-%22comments%20closed%22";
            keyValueListMessageBoardsAndForums.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListMessageBoardsAndForums);
   
            //4. option4: Advanced Search Parameters
   
            //all this group append keyword to end
            footprintPair.BAppendKeywordToEnd = true;
   
            keyValueList keyValueListAdvancedSearchParameters = new keyValueList();
            keyValueListAdvancedSearchParameters.Key = "Advanced Search Parameters";
            keyValueListAdvancedSearchParameters.ValuePairList = new List<footprintPair>();
   
               
            footprintPair.ShowString = "URLs Containing Keyword";
            //"allinurl":
            //footprintPair.EncodedAppend = "%22allinurl%22%3A";
            //allinurl:
            footprintPair.EncodedAppend = "allinurl%3A";
            keyValueListAdvancedSearchParameters.ValuePairList.Add(footprintPair);
               
            footprintPair.ShowString = "Page Titles Containing Keyword";
            //allintitle:
            footprintPair.EncodedAppend = "allintitle%3A";
            keyValueListAdvancedSearchParameters.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Search Anchor Text";
            //allinanchor:
            footprintPair.EncodedAppend = "allinanchor%3A";
            keyValueListAdvancedSearchParameters.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Related (enter a domain)";
            //related:
            footprintPair.EncodedAppend = "related%3A";
            keyValueListAdvancedSearchParameters.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListAdvancedSearchParameters);
   
            //restore to normal
            footprintPair.BAppendKeywordToEnd = false;
   
            //5. option5: Sponsor/Donate
            keyValueList keyValueListSponsorDonate = new keyValueList();
            keyValueListSponsorDonate.Key = "Sponsor/Donate";
            keyValueListSponsorDonate.ValuePairList = new List<footprintPair>();
   
            footprintPair.ShowString = "Sponsor";
            //inurl:sponsors AND link
            footprintPair.EncodedAppend = "inurl%3Asponsors%20AND%20link";
            keyValueListSponsorDonate.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Sponsorship";
            //"sponsorship"
            footprintPair.EncodedAppend = "%22sponsorship%22";
            keyValueListSponsorDonate.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Benefactors";
            //"benefactors"
            footprintPair.EncodedAppend = "%22benefactors%22";
            keyValueListSponsorDonate.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Sponsor Charity";
            //"sponsor charity"
            footprintPair.EncodedAppend = "%22sponsor%20charity%22";
            keyValueListSponsorDonate.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Donate";
            //"donate"
            footprintPair.EncodedAppend = "%22donate%22";
            keyValueListSponsorDonate.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Donations";
            //"donations"
            footprintPair.EncodedAppend = "%22donations%22";
            keyValueListSponsorDonate.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Donors";
            //"donors"
            footprintPair.EncodedAppend = "%22donors%22";
            keyValueListSponsorDonate.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListSponsorDonate);
   
            //6. option6: Wiki / Media Wiki Pages
            keyValueList keyValueListWikiMediaWikiPages = new keyValueList();
            keyValueListWikiMediaWikiPages.Key = "Wiki / Media Wiki Pages";
            keyValueListWikiMediaWikiPages.ValuePairList = new List<footprintPair>();
   
            footprintPair.ShowString = "Wiki sites";
            //"inurl:wiki/index.php?title=" OR "inurl:mediawiki/index.php" OR "allinurl:http://mediawiki."
            footprintPair.EncodedAppend = "%22inurl%3Awiki/index.php%3Ftitle%3D%22%20OR%20%22inurl%3Amediawiki/index.php%22%20OR%20%22allinurl%3Ahttp%3A//mediawiki.%22";
            keyValueListWikiMediaWikiPages.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Outdated Wiki Content";
            //"This article is outdated"
            footprintPair.EncodedAppend = "%22This%20article%20is%20outdated%22";
            keyValueListWikiMediaWikiPages.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListWikiMediaWikiPages);
   
            //7. option7: Other Queries
            keyValueList keyValueListOtherQueries = new keyValueList();
            keyValueListOtherQueries.Key = "Other Queries";
            keyValueListOtherQueries.ValuePairList = new List<footprintPair>();
   
            footprintPair.ShowString = "Directory Add URL";
            //"dir-addurl"
            footprintPair.EncodedAppend = "%22dir-addurl%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Directory Site";
            //"dir-addsite"
            footprintPair.EncodedAppend = "%22dir-addsite%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Hubpages - Hot Hubs";
            //site:hubpages.com "hot hubs"
            footprintPair.EncodedAppend = "site%3Ahubpages.com%20%22hot%20hubs%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Squidoo lenses - Add To List";
            //"add to this list" site:squidoo.com
            footprintPair.EncodedAppend = "%22add+to+this+list%22%20site%3Asquidoo.com";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Social Bookmarking";
            //"Store, share and tag your favourite links"
            footprintPair.EncodedAppend = "%22Store%2C%20share%20and%20tag%20your%20favourite%20links%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Social Bookmarking 2.0";
            //"Bookmarking the web 2.0"
            footprintPair.EncodedAppend = "%22Bookmarking%20the%20web%202.0%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Guestbooks";
            //"intext:"Sign * Guestbook" intext:"back to guestbook" intext:"administration" intext:"Homepage""
            footprintPair.EncodedAppend = "%22intext%3A%22Sign%20*%20Guestbook%22%20intext%3A%22back%20to%20guestbook%22%20intext%3A%22administration%22%20intext%3A%22Homepage%22%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Suggest or Submit URL";
            //"Submit a link" OR "Submit a site" OR "Submit URL" OR "Submit an URL" OR "Suggest a link" OR "Suggest a site" OR "Suggest URL" OR "Suggest an URL"
            footprintPair.EncodedAppend = "%22Submit%20a%20link%22%20OR%20%22Submit%20a%20site%22%20OR%20%22Submit%20URL%22%20OR%20%22Submit%20an%20URL%22%20OR%20%22Suggest%20a%20link%22%20OR%20%22Suggest%20a%20site%22%20OR%20%22Suggest%20URL%22%20OR%20%22Suggest%20an%20URL%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Warp Framework (Joomla)";
            //"Powered by Warp Theme Framework"
            footprintPair.EncodedAppend = "%22Powered%20by%20Warp%20Theme%20Framework%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Angelae8654 Site Profiles";
            //"angelae8654"
            footprintPair.EncodedAppend = "%22angelae8654%22";
            keyValueListOtherQueries.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListOtherQueries);
   
            //8. option8: Link Bartering
            keyValueList keyValueListLinkBartering = new keyValueList();
            keyValueListLinkBartering.Key = "Link Bartering";
            keyValueListLinkBartering.ValuePairList = new List<footprintPair>();
   
            footprintPair.ShowString = "Buy Blog Posts";
            //"Buy Blog Posts" OR "Buy Blog Post" OR "Sponsor Blog Post"
            footprintPair.EncodedAppend = "%22Buy%20Blog%20Posts%22%20OR%20%22Buy%20Blog%20Post%22%20OR%20%22Sponsor%20Blog%20Post%22";
            keyValueListLinkBartering.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Buy Link";
            //"Buy Links" OR "Buy Bulk Links" OR "Purchase Links" OR "Advertise Here" OR "Sponsor Us" OR "Cheap Links"
            footprintPair.EncodedAppend = "%22Buy%20Links%22%20OR%20%22Buy%20Bulk%20Links%22%20OR%20%22Purchase%20Links%22%20OR%20%22Advertise%20Here%22%20OR%20%22Sponsor%20Us%22%20OR%20%22Cheap%20Links%22";
            keyValueListLinkBartering.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Link Exchange";
            //"Link Exchange" OR "Link Trade" OR "Link Ring" OR "Web Ring"
            footprintPair.EncodedAppend = "%22Link%20Exchange%22%20OR%20%22Link%20Trade%22%20OR%20%22Link%20Ring%22%20OR%20%22Web%20Ring%22";
            keyValueListLinkBartering.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Link Barter Service";
            //"Link Bartering Service" OR "Link Building service" OR "Cheap Links"
            footprintPair.EncodedAppend = "%22Link%20Bartering%20Service%22%20OR%20%22Link%20Building%20service%22%20OR%20%22Cheap%20Links%22";
            keyValueListLinkBartering.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListLinkBartering);
   
            //9. option9: Site Specific Sites
            keyValueList keyValueListSiteSpecificSites = new keyValueList();
            keyValueListSiteSpecificSites.Key = "Site Specific Sites";
            keyValueListSiteSpecificSites.ValuePairList = new List<footprintPair>();
   
            footprintPair.ShowString = "Facebook";
            //"site:facebook.com"
            footprintPair.EncodedAppend = "%22site%3Afacebook.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Twitter";
            //"site:twitter.com"
            footprintPair.EncodedAppend = "%22site%3Atwitter.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Pinterest";
            //"site:pinterest.com"
            footprintPair.EncodedAppend = "%22site%3Apinterest.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Google Groups";
            //"site:groups.google.com"
            footprintPair.EncodedAppend = "%22site%3Agroups.google.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Scribd";
            //"site:scribd.com"
            footprintPair.EncodedAppend = "%22site%3Ascribd.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Slideshare";
            //"site:slideshare.net"
            footprintPair.EncodedAppend = "%22site%3Aslideshare.net%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Wikipedia";
            //"site:wikipedia.org"
            footprintPair.EncodedAppend = "%22site%3Awikipedia.org%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Tumblr";
            //"site:tumblr.com"
            footprintPair.EncodedAppend = "%22site%3Atumblr.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Typepad";
            //"site:typepad.com"
            footprintPair.EncodedAppend = "%22site%3Atypepad.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Buzzfeed";
            //"site:buzzfeed.com"
            footprintPair.EncodedAppend = "%22site%3Abuzzfeed.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "NYTimes";
            //"site:nytimes.com"
            footprintPair.EncodedAppend = "%22site%3Anytimes.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            footprintPair.ShowString = "Huffington Post";
            //"site:huffingtonpost.com"
            footprintPair.EncodedAppend = "%22site%3Ahuffingtonpost.com%22";
            keyValueListSiteSpecificSites.ValuePairList.Add(footprintPair);
   
            gFootprintTypeSelList.Add(keyValueListSiteSpecificSites);
   
            //set footprint type data source
            cmbFootprintType.DataSource = gFootprintTypeSelList;
            cmbFootprintType.DisplayMember = "key";
        }
   
        private void initChaseFootprint()
        {
            //init combox
            initFootprintTypeAndFootprintString();
   
            //init defult selection
            cmbFootprintType.SelectedIndex = 0;
        }
   
        private void frmDropMyLink_Load(object sender, EventArgs e)
        {
#if DEBUG
            txbKeyword.Text = "weight loss";
            cmbSearchType.SelectedIndex = 7;
            //txbExportFilename.Text = "AuthorityCommentFinderSearchResult";
            //txbExportFilename.Text = tpgDropmylink.Text + "SearchResult";
            txbExportFilename.Text = "CurrentSearchResult";
#endif
            this.WindowState = FormWindowState.Maximized;
            initSearchResultGridView();
   
            initChaseFootprint();
        }
   
        //update UI according current status
        private void updateUI()
        {
            if (curSearchStatus == search_status.SEARCH_STATUS_STOPPED)
            {
                btnSearch.Enabled = true;
                btnSearch.Text = "Search";
   
                btnExportToCsv.Enabled = true;
                btnExportToExcel.Enabled = true;
                grbActions.Enabled = true;
   
                btnStopSearch.Enabled = false;
            }
            else if (curSearchStatus == search_status.SEARCH_STATUS_SEARCHING)
            {
                btnSearch.Enabled = false;
                btnSearch.Text = "Searching";
   
                grbActions.Enabled = false;
                btnExportToCsv.Enabled = false;
                btnExportToExcel.Enabled = false;
   
                btnStopSearch.Enabled = true;
            }
        }
   
        string getCurSearchTail()
        {
            //weight loss
   
            //weight loss site:.edu inurl:blog "post a comment" -"you must be logged in"
            //weight loss site:.gov inurl:blog "post a comment" -"you must be logged in"
            //weight loss "Allowed HTML tags:"
            //weight loss "angelae8654"
            //weight loss "This blog uses premium CommentLuv" -"The version of CommentLuv on this site is no longer supported."
            //weight loss "Notify me of follow-up comments?" "Submit the word you see below:"
            //weight loss "powered by expressionengine"
            //weight loss site:hubpages.com "hot hubs"
            //weight loss "Enter YourName@YourKeywords"
            //weight loss "get livefyre" "comment help" -"Comments have been disabled for this post"
            //weight loss "if you have a website, link to it here" "post a new comment"
            //weight loss "add to this list" site:squidoo.com
               
            /*
                .edu Blogs
                .gov Blogs
                Anchor Text In Comment Blogs
                Angela's Backlinks
                CommentLuv Premium Blogs
                Do Follow Comment Blogs
                Expression Engine Forums
                Hubpages - Hot Hubs
                KeywordLuv Blogs
                LiveFyre Blogs
                Intense Debate Blogs
                Squidoo lenses - Add To List
             * */
   
   
            string curSearchType = "";
            switch (cmbSearchType.SelectedIndex)
            {
                case 0:
                    curSearchType = " site:.edu inurl:blog \"post a comment\" -\"you must be logged in\""; //.edu Blogs
                    break;
                case 1:
                    curSearchType = " site:.gov inurl:blog \"post a comment\" -\"you must be logged in\"";//.gov Blogs
                    break;
                case 2:
                    curSearchType = " \"Allowed HTML tags:\"";//Anchor Text In Comment Blogs
                    break;
                case 3:
                    curSearchType = " \"angelae8654\"";//Angela's Backlinks
                    break;
                case 4:
                    curSearchType = " \"This blog uses premium CommentLuv\" -\"The version of CommentLuv on this site is no longer supported.\"";//CommentLuv Premium Blogs
                    break;
                case 5:
                    curSearchType = " \"Notify me of follow-up comments?\" \"Submit the word you see below:\"";//Do Follow Comment Blogs
                    break;
                case 6:
                    curSearchType = " \"powered by expressionengine\"";//Expression Engine Forums
                    break;
                case 7:
                    curSearchType = " site:hubpages.com \"hot hubs\"";//Hubpages - Hot Hubs
                    break;
                case 8:
                    curSearchType = " \"Enter YourName@YourKeywords\"";//KeywordLuv Blogs
                    break;
                case 9:
                    curSearchType = " \"get livefyre\" \"comment help\" -\"Comments have been disabled for this post\"";//LiveFyre Blogs
                    break;
                case 10:
                    curSearchType = " \"if you have a website, link to it here\" \"post a new comment\"";//Intense Debate Blogs
                    break;
                case 11:
                    curSearchType = " \"add to this list\" site:squidoo.com";//Squidoo lenses - Add To List
                    break;
                default:
                    curSearchType = "";
                    break;
   
            }
            return curSearchType;
        }
           
        void processEachSearchItem(searchItemInfo singleItemInfo)
        {
            singleItemInfo.domainUrl = crifanLib.getDomainUrl(singleItemInfo.url);
#if LATE_CALC_RANK
            singleItemInfo.pageRank = invalidRankValue;
            singleItemInfo.alexaRank = invalidRankValue;
#else
            singleItemInfo.pageRank = crifanLib.getDomainPageRank(singleItemInfo.domainUrl);
            singleItemInfo.alexaRank = crifanLib.getDomainAlexaRank(singleItemInfo.domainUrl);
#endif
   
            dgvSearchResult.Rows.Add(
                singleItemInfo.title,
                singleItemInfo.url,
                singleItemInfo.pageRank,
                singleItemInfo.alexaRank);
   
            visitUrlColumn.DataGridView.Rows[dgvSearchResult.Rows.Count - 1].Cells[visitUrlColumnIdx].Value = "View Page";
            visitUrlColumn.DataGridView.Rows[dgvSearchResult.Rows.Count - 1].Cells[visitUrlColumnIdx].Tag = singleItemInfo.url;
   
            crifanLib.dgvDrawHeaderNum(dgvSearchResult);
   
            //update UI
            System.Windows.Forms.Application.DoEvents();
        }
   
        public struct searchItemInfo
        {
            public string title;
            public string url;
            public string domainUrl;
            public int pageRank;
            public int alexaRank;
        };
           
        private void parseSinglePageHtml(string singlePageGoogleHtml)
        {
            //<h3 class="r"><a href="http://bloodcenter.stanford.edu/blog/archives/2011/04/type-2-diabetes.html" target=_blank class=l onmousedown="return rwt(this,'','','','11','AFQjCNEbtRkzYDSJUigURl6AUHmlBGtY-A','','0CDAQFjAAOAo','','',event)">Type-2 Diabetes an Autoimmune Disease? - Hemoblogin - School <b>...</b></a></h3>
            HtmlAgilityPack.HtmlDocument htmlDoc = crifanLib.htmlToHtmlDoc(singlePageGoogleHtml);
            HtmlNode rootHtmlNode = htmlDoc.DocumentNode;
            HtmlNodeCollection h3aHtmlNodes = rootHtmlNode.SelectNodes("//h3[@class='r']/a");
            foreach (HtmlNode h3aNode in h3aHtmlNodes)
            {
                if (needContinueSearch)
                {
                    searchItemInfo singleItemInfo = new searchItemInfo();
   
                    //InnerHtml
                    //"Losing <em>weight</em> and belly fat improves sleep - Harvard Health <b>...</b>"
                    //InnerText:
                    //"Losing weight and belly fat improves sleep - Harvard Health ..."
                    string undecodedTitle = h3aNode.InnerText;
                    singleItemInfo.title = HttpUtility.HtmlDecode(undecodedTitle);
   
                    singleItemInfo.url = h3aNode.Attributes["href"].Value;
   
                    processEachSearchItem(singleItemInfo);
                }
                else
                {
                    break;
                }
            }
        }
   
        //private void processXjs(string respHtml)
        //{
        //    //extract xjs url
        //    //google.dljp('/xjs/_/js/s/c,sb,cr,cdos,vm,tbui,mb,wobnm,cfm,abd,bihu,kp,lu,m,tnv,amcl,hv,lc,ob,r,rsn,sf,sfa,shb,tbpr,hsm,j,pcc,csi/rt\x3dj/ver\x3dADVrJ2nu1R4.en_US./am\x3dAAE/d\x3d1/sv\x3d1/rs\x3dAItRSTP8CWiu2moML2ZpukqdhJfoo-cmkA');
        //    string xjsUrl = "";
        //    if (crifanLib.extractSingleStr(@"google\.dljp\('(.+?)'\);", respHtml, out xjsUrl))
        //    {
        //        //http://www.google.com.hk/xjs/_/js/s/c,sb,cr,cdos,tbui,mb,wobnm,cfm,abd,bihu,kp,lu,m,tnv,amcl,hv,lc,ob,r,rsn,sf,sfa,shb,tbpr,hsm,pcc,csi/rt=j/ver=ADVrJ2nu1R4.en_US./am=AAE/d=1/sv=1/rs=AItRSTP8CWiu2moML2ZpukqdhJfoo-cmkA
        //        xjsUrl = "http://www.google.com.hk" + xjsUrl;
        //        xjsUrl = HttpUtility.HtmlDecode(xjsUrl);
        //        string tmpXjsRespHtml = crifanLib.getUrlRespHtml(xjsUrl);
        //    }
        //}
   
        private void afterSearch()
        {
#if LATE_CALC_RANK
            for (int rowIdx = 0; rowIdx < dgvSearchResult.Rows.Count; rowIdx++)
            {
                if (needContinueSearch)
                {
                    DataGridViewRow curRow = dgvSearchResult.Rows[rowIdx];
                    DataGridViewCell urlCell = curRow.Cells[urlColumnIdx];
                    string domainUrl = crifanLib.getDomainUrl(urlCell.Value.ToString());
                    DataGridViewCell pageRankCell = curRow.Cells[pageRankColumnIdx];
   
                    if (pageRankCell.Value.Equals(invalidRankValue))
                    {
                        pageRankCell.Value = crifanLib.getDomainPageRank(domainUrl);
                    }
                    else
                    {
                        //not do again
                    }
   
                    DataGridViewCell alexaRankCell = curRow.Cells[alexaRankColumnIdx];
                    if (alexaRankCell.Value.Equals(invalidRankValue))
                    {
                        alexaRankCell.Value = crifanLib.getDomainAlexaRank(domainUrl);
                    }
                    else
                    {
                        //not do again
                    }
                }
                else
                {
                    break;
                }
            }
#endif
        }
   
        private void searchAndParse(string searchStr)
        {
            Dictionary<string, string> queryPara;
            Dictionary<string, string> headerDict;
            string curGoogleSearchUrl;
            string curSearchRespHtml;
            string curReferer;
            //string ei = "";
   
            //1. for get cookie and related url
            string googleUrl = "http://www.google.com.hk/";
            string tmpRespHtml = crifanLib.getUrlRespHtml_multiTry(googleUrl);
            //processXjs(tmpRespHtml);
   
            //2. do first search
            //weight loss site:.edu inurl:blog "post a comment" -"you must be logged in"
            //http://www.google.com.hk/search?newwindow=1&safe=strict&site=&source=hp&q=weight+loss+site%3A.edu+inurl%3Ablog+%22post+a+comment%22+-%22you+must+be+logged+in%22&btnK=Google+Search
   
            //http://www.google.com.hk/search
            //?newwindow=1
            //&safe=strict
            //&site=
            //&source=hp
            //&q=weight+loss+site%3A.edu+inurl%3Ablog+%22post+a+comment%22+-%22you+must+be+logged+in%22
            //&btnK=Google+Search
            string firstGoogleSearchUrl = "http://www.google.com.hk/search?";
            queryPara = new Dictionary<string, string>();
            queryPara.Add("newwindow", "1");
            queryPara.Add("safe", "strict");
            queryPara.Add("source", "hp");
            queryPara.Add("q", searchStr);
            queryPara.Add("btnK", "Google Search");
   
            queryPara.Add("site", "");
            //queryPara.Add("site", "webhp");
   
               
            //firstGoogleSearchUrl += crifanLib.quoteParas(queryPara);
            firstGoogleSearchUrl += crifanLib.quoteParas(queryPara, false);
            //http://www.google.com.hk/search?newwindow=1&safe=strict&site=&source=hp&q=weight+loss+site%3a.edu+inurl%3ablog+%22post+a+comment%22+-%22you+must+be+logged+in%22&btnK=Google+Search
   
            curReferer = googleUrl;
            curGoogleSearchUrl = firstGoogleSearchUrl;
   
            //3. continue to search current page and next page ...
            while(needContinueSearch)
            {
                headerDict = new Dictionary<string,string>();
                headerDict.Add("referer", curReferer);
                curSearchRespHtml = crifanLib.getUrlRespHtml_multiTry(curGoogleSearchUrl, headerDict: headerDict);
                   
                //processXjs(tmpRespHtml);
   
                parseSinglePageHtml(curSearchRespHtml);
                if (!needContinueSearch)
                {
                    break;
                }
   
                ////window.google={kEI:"XZp2UczlE8nYigeK5IHgCg"
                ////get ei for next page
                //if(crifanLib.extractSingleStr(@"window.google={kEI:""(\w+)""", curSearchRespHtml, out ei))
                //{
   
                //}
   
                //check need get more page or not
                //<a href="/search?q=weight+loss+site:.edu+inurl:blog+%22post+a+comment%22+-%22you+must+be+logged+in%22&amp;newwindow=1&amp;safe=strict&amp;ei=XZp2UczlE8nYigeK5IHgCg&amp;start=10&amp;sa=N" class="pn" id="pnnext" style="text-decoration:none;text-align:left"><span class="csb gbil ch" style="background-position:-96px 0;width:71px"></span><span style="display:block;margin-left:53px;text-decoration:underline">Next</span></a>
                HtmlAgilityPack.HtmlDocument htmlDoc = crifanLib.htmlToHtmlDoc(curSearchRespHtml);
                HtmlNode rootHtmlNode = htmlDoc.DocumentNode;
                HtmlNode nextHtmlNode = rootHtmlNode.SelectSingleNode("//a[@id='pnnext' and @class='pn']");
                if(nextHtmlNode != null)
                {
                    //before update google url, store it to refer for next search use
                    curReferer = curGoogleSearchUrl;
   
                    //Method 2: extract net page url
                    string hrefStr = nextHtmlNode.Attributes["href"].Value;
                    //string decodedUrl = HttpUtility.HtmlDecode(hrefStr);
                    //string decodedUrl = HttpUtility.UrlDecode(hrefStr);
   
                    //string nextPageUrl = googleUrl + hrefStr;
                    string encodedUrl = "http://www.google.com.hk" + hrefStr;
   
                    //http://www.google.com.hk/search?q=weight+loss+site:.edu+inurl:blog+%22post+a+comment%22+-%22you+must+be+logged+in%22&newwindow=1&safe=strict&ei=XZp2UczlE8nYigeK5IHgCg&start=10&sa=N
                    //"http://www.google.com.hk/search?q=weight+loss+%22powered+by+expressionengine%22&amp;newwindow=1&amp;safe=strict&amp;ei=RKZ3Ubf2JqqUiQeN5YHQBg&amp;start=10&amp;sa=N"
                    string htmlDecoded = HttpUtility.HtmlDecode(encodedUrl);
                    //"http://www.google.com.hk/search?q=weight+loss+%22powered+by+expressionengine%22&newwindow=1&safe=strict&ei=RKZ3Ubf2JqqUiQeN5YHQBg&start=10&sa=N"
                    curGoogleSearchUrl = htmlDecoded;
                       
                    ////method 1: generate nex page url
                    ////http://www.google.com.hk/search?q=weight+loss+site:.edu+inurl:blog+%22post+a+comment%22+-%22you+must+be+logged+in%22&newwindow=1&safe=strict&ei=XZp2UczlE8nYigeK5IHgCg&start=10&sa=N
                    //string startNumStr = "";
                    //if (crifanLib.extractSingleStr(@"&start=(\d+)&", curGoogleSearchUrl, out startNumStr))
                    //{
                    //    int startNumInt = Int32.Parse(startNumStr);
                    //    int nextStartNumInt = startNumInt + 10;
                    //    string nextStartNumStr = nextStartNumInt.ToString();
   
                    //    curGoogleSearchUrl = curGoogleSearchUrl.Replace("&start=" + startNumStr, "&start=" + nextStartNumStr);
                    //}
                    //else
                    //{
                    //    //is the first page
                    //    //http://www.google.com.hk/search?newwindow=1&safe=strict&source=hp&q=weight+loss+%22Allowed+HTML+tags%3a%22&btnK=Google+Search&site=
                                                   
                    //    //Method 2: extract net page url
                    //    string hrefStr = nextHtmlNode.Attributes["href"].Value;
                    //    //string decodedUrl = HttpUtility.HtmlDecode(hrefStr);
                    //    //string decodedUrl = HttpUtility.UrlDecode(hrefStr);
   
                    //    //string nextPageUrl = googleUrl + hrefStr;
                    //    string encodedUrl = "http://www.google.com.hk" + hrefStr;
   
                    //    //http://www.google.com.hk/search?q=weight+loss+site:.edu+inurl:blog+%22post+a+comment%22+-%22you+must+be+logged+in%22&newwindow=1&safe=strict&ei=XZp2UczlE8nYigeK5IHgCg&start=10&sa=N
                    //    //"http://www.google.com.hk/search?q=weight+loss+%22powered+by+expressionengine%22&amp;newwindow=1&amp;safe=strict&amp;ei=RKZ3Ubf2JqqUiQeN5YHQBg&amp;start=10&amp;sa=N"
                    //    string htmlDecoded = HttpUtility.HtmlDecode(encodedUrl);
                    //    //"http://www.google.com.hk/search?q=weight+loss+%22powered+by+expressionengine%22&newwindow=1&safe=strict&ei=RKZ3Ubf2JqqUiQeN5YHQBg&start=10&sa=N"
                    //    curGoogleSearchUrl = htmlDecoded;
                    //}
   
                    needContinueSearch = true;
                }
                else
                {
                    afterSearch();
   
                    needContinueSearch = false;
                    break;
                }
            }           
        }
   
        private void startSearchDropmylink()
        {
            //generate search string
            string searchStr = "";
            searchStr += txbKeyword.Text;
            searchStr += getCurSearchTail();
   
            searchAndParse(searchStr);
        }
   
        private void startSearchChaseFootprint()
        {
            ////choose: Sponsor/Donate -> Sponsor Charity
            //// ->
            ////http://www.google.com.hk/search?q=weight%20loss+%22sponsor%20charity%22
            ////->
            ////http://www.google.com.hk/search?q=weight loss+"sponsor charity"
            //string strCurFootprint = getCurrentFootprint(); //"Sponsor Charity"
            //string strEncodedFootprint = HttpUtility.UrlPathEncode(strCurFootprint); //"Sponsor%20Charity"
   
            //string strKeyword = txbKeywordChaseFootprint.Text; //"weight loss"
            //string strEncodedKeyword = HttpUtility.UrlPathEncode(strKeyword); //"weight%20loss"
   
            //string strUrlPrefix = "http://www.google.com.hk/search?q=";
            //string strEncodedFullFootprintUrl = String.Format("{0}{1}+%22{2}%22", strUrlPrefix, strEncodedKeyword, strEncodedFootprint); //"http://www.google.com.hk/search?q=weight%20loss+%22Sponsor%20Charity%22"
   
   
            //"%22Powered%20by%20JComments%22"
            footprintPair curFootprintPair = getCurrentFootprintPair();
            string strCurEncodedRealAppendFootprint = curFootprintPair.EncodedAppend; //"%22guest%20blogger%22%20OR%20%22guest%20post%22%20OR%20%22guest%20article%22%20OR%20%22Add%20Guest%20Post%22%20OR%20%22Submit%20Guest%20Post%22%20OR%20%22Submit%20a%20Guest%20Article%22%20OR%20%22Guest%20Post%20Guidelines%22"
   
            string strKeyword = txbKeywordChaseFootprint.Text; //"weight loss"
            string strEncodedKeyword = HttpUtility.UrlPathEncode(strKeyword); //"weight%20loss"
            string strUrlPrefix = "http://www.google.com.hk/search?q=";
            string strEncodedFullFootprintUrl = "";
            if (curFootprintPair.BAppendKeywordToEnd)
            {
                strEncodedFullFootprintUrl = strUrlPrefix + strCurEncodedRealAppendFootprint + "+" + strEncodedKeyword; //"http://www.google.com.hk/search?q=allinurl%3A+weight%20loss"
            }
            else
            {
                strEncodedFullFootprintUrl = strUrlPrefix + strEncodedKeyword + "+" + strCurEncodedRealAppendFootprint; //"http://www.google.com.hk/search?q=weight%20loss+%22Powered%20by%20JComments%22"
            }
   
            //http://www.google.com.hk/search?q=weight%20loss+%22Sponsor%20Charity%22
            wbsChaseFootprint.Url = new Uri(strEncodedFullFootprintUrl);
        }
   
        private void startSearch()
        {
            if (tbcSearch.SelectedTab == tpgDropmylink)
            {
                startSearchDropmylink();
            }
            else if (tbcSearch.SelectedTab == tpgChaseFootprint)
            {
                startSearchChaseFootprint();
            }
        }
   
        private void clearSearchResult()
        {
            crifanLib.dgvClearContent(dgvSearchResult);
        }
   
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (curSearchStatus == search_status.SEARCH_STATUS_STOPPED)
            {
                clearSearchResult();
   
                needContinueSearch = true;
   
                //start search
                curSearchStatus = search_status.SEARCH_STATUS_SEARCHING;
                updateUI();
   
                startSearch();
   
                curSearchStatus = search_status.SEARCH_STATUS_STOPPED;
                updateUI();
            }
        }
   
        private void stopSearch()
        {
            if (tbcSearch.SelectedTab == tpgDropmylink)
            {
                   
            }
            else if (tbcSearch.SelectedTab == tpgChaseFootprint)
            {
                wbsChaseFootprint.Stop();
                //afterSearchComplete();
            }
        }
           
        private void btnStopSearch_Click(object sender, EventArgs e)
        {
            if (curSearchStatus == search_status.SEARCH_STATUS_SEARCHING)
            {
                curSearchStatus = search_status.SEARCH_STATUS_STOPPED;
                updateUI();
   
                //do stop things
                stopSearch();
                needContinueSearch = false;
            }
        }
   
        private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            string saveFolderPath = crifanLib.getSaveFolder(fbdSaveFolder);
            if ((saveFolderPath == null) || (saveFolderPath == ""))
            {
                return;
            }
   
            string outputFilename = txbExportFilename.Text + ".xls";
            string fullFilename = Path.Combine(saveFolderPath, outputFilename);
   
            List<int> omitColumnIdxList = new List<int>();
            //omit the last column: View page
            omitColumnIdxList.Add(dgvSearchResult.ColumnCount - 1);
   
            crifanLib.dgvExportToExcel(dgvSearchResult, fullFilename, omitColumnIdxList: omitColumnIdxList);
   
            crifanLib.openFolderAndSelectFile(fullFilename);
        }
   
        private void btnExportToCsv_Click(object sender, EventArgs e)
        {
            string saveFolderPath = crifanLib.getSaveFolder(fbdSaveFolder);
            if ((saveFolderPath == null) || (saveFolderPath == ""))
            {
                return;
            }
   
            string outputFilename = txbExportFilename.Text + ".csv";
            string fullFilename = Path.Combine(saveFolderPath, outputFilename);
   
            List<int> omitColumnIdxList = new List<int>();
            //omit the last column: View page
            omitColumnIdxList.Add(dgvSearchResult.ColumnCount - 1);
   
            crifanLib.dgvExportToCsv(dgvSearchResult, fullFilename, omitColumnIdxList: omitColumnIdxList);
   
            //after save file
            crifanLib.openFolderAndSelectFile(fullFilename);
        }
   
        private void btnClearAll_Click(object sender, EventArgs e)
        {
            crifanLib.dgvClearContent(dgvSearchResult);
        }
           
        private void cmbFootprintType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbFootprintType.SelectedItem != null)
            {
                //keyValueList curSelFootprintType = (keyValueList)cmbFootprintType.SelectedItem;
                //List<string> footprintSelectionValueList = curSelFootprintType.ValuePairList;
                //cmbFootprintStr.DataSource = footprintSelectionValueList;
   
                keyValueList curSelFootprintType = (keyValueList)cmbFootprintType.SelectedItem;
                List<footprintPair> footprintSelectionValueList = curSelFootprintType.ValuePairList;
                cmbFootprintStr.DataSource = footprintSelectionValueList;
                cmbFootprintStr.DisplayMember = "showString";
            }
        }
   
        private footprintPair getCurrentFootprintPair()
        {
            footprintPair curFootprintPair = new footprintPair();
            if (cmbFootprintStr.SelectedItem != null)
            {
                //curFootprint = (string)cmbFootprintStr.SelectedItem;
                curFootprintPair = (footprintPair)cmbFootprintStr.SelectedItem;
            }
            return curFootprintPair;
        }
   
        //private void searchChaseFootprint()
        //{
        //}
   
   
        ////update UI according current status
        //private void updateUI_footprint()
        //{
        //    if (curSearchStatus_footprint == search_status.SEARCH_STATUS_STOPPED)
        //    {
        //        btnSearchChaseFootprint.Enabled = true;
        //        btnSearchChaseFootprint.Text = "Search";
   
        //        btnStopChaseFootprint.Enabled = false;
        //    }
        //    else if (curSearchStatus_footprint == search_status.SEARCH_STATUS_SEARCHING)
        //    {
        //        btnSearchChaseFootprint.Enabled = false;
        //        btnSearchChaseFootprint.Text = "Searching";
   
        //        btnStopChaseFootprint.Enabled = true;
        //    }
        //}
   
        //private void btnSearchChaseFootprint_Click(object sender, EventArgs e)
        //{
        //    if (curSearchStatus_footprint == search_status.SEARCH_STATUS_STOPPED)
        //    {
        //        txbOutput.Text = "";
   
        //        needContinueSearch = true;
   
        //        //start search
        //        curSearchStatus_footprint = search_status.SEARCH_STATUS_SEARCHING;
        //        updateUI_footprint();
   
                   
        //    }
        //}
   
        //private void afterSearchComplete()
        //{
        //    curSearchStatus_footprint = search_status.SEARCH_STATUS_STOPPED;
        //    updateUI_footprint();
        //}
   
        private void wbsChaseFootprint_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //if (wbsChaseFootprint.ReadyState != WebBrowserReadyState.Complete)
            //{
            //    //not actually complete, do nothing
            //    return;
            //}
   
            if (!e.Url.Equals(wbsChaseFootprint.Url))
            {
                //not actually complete, do nothing
                return;
            }
   
            string curHtml = wbsChaseFootprint.DocumentText;
            //System.Windows.Forms.HtmlDocument htmlDoc = wbsChaseFootprint.Document;
   
            List<crifanLibGoogle.googleSearchResultItem> resultItemList = google.extractGoogleSearchResult("", curHtml);
            if ((resultItemList != null) && (resultItemList.Count > 0))
            {
                //txbOutput.Text = "";
   
                foreach (crifanLibGoogle.googleSearchResultItem singleResultItem in resultItemList)
                {
                    //txbOutput.Text += singleResultItem.Url + Environment.NewLine;
   
                    searchItemInfo singleItemInfo = new searchItemInfo();
   
                    singleItemInfo.title = singleResultItem.Title;
                    singleItemInfo.url = singleResultItem.Url;
   
                    processEachSearchItem(singleItemInfo);
                }
            }
   
            //afterSearchComplete();
            //debug
            afterSearch();
        }
   
        private void dgvSearchResult_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.RowIndex >= 0) && (e.ColumnIndex == visitUrlColumnIdx))
            {
                DataGridViewButtonCell clickedButtonCell = (DataGridViewButtonCell)dgvSearchResult.Rows[e.RowIndex].Cells[e.ColumnIndex];
                System.Diagnostics.Process.Start(clickedButtonCell.Tag.ToString());
            }
        }
   
   
        ////sometime WebBrowser can not goto DocumentCompleted
        ////so need here force stop
        //private void btnStopChaseFootprint_Click(object sender, EventArgs e)
        //{
        //    wbsChaseFootprint.Stop();
        //    afterSearchComplete();
        //}
    }
}

【总结】

转载请注明:在路上 » 【代码分享】C#代码:AuthorityCommentFinder – 模拟(chasethefootprint和DropMyLink添加footprint后去)google搜索

80 queries in 0.298 seconds, using 22.32MB memory