mshtml简单代码获得Google Adsense广告路径[代码]


        最近分析了一下Google Adsense投放的广告,呵呵,使用mshtml很简单的代码得到Google Adsense的广告的地址,没什么用处,呵呵,只是玩玩而已,声明不会对Google Adsense进行作弊,不然会被Google给kick out的,呵呵……
        至于原理很简单:Google利用Javascript在目的网页上生成一个name为google_ads_frame的iframe,该iframe中的网页上包含一个id为aw0的超级链接(代码中分析的是按钮型的广告,其中只有一个超级链接,多个超级的原理也是一样的,超级链接的id的格式为“aw+序数”),这些用mshtml都很容易得到。
        需要提到的是广告中的超级链接的类型(用mshtml分析)为HTMLAnchorElementClass。如果不知道类型怎么办,可以用this.doc.all.item("aw0", null).GetType().ToString()来得到,这是使用mshtml时的一个技巧。



代码:

  1using System;
  2using System.Drawing;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Windows.Forms;
  6
  7namespace Google_Adsense
  8{
  9    /// <summary>
 10    /// frmGetAdLink 的摘要说明。
 11    /// </summary>

 12    public class frmGetAdLink : System.Windows.Forms.Form
 13    {
 14        private System.Windows.Forms.Timer timRefresh;
 15        private System.Windows.Forms.Panel panBottom;
 16        private System.Windows.Forms.Button btnLink;
 17        private System.Windows.Forms.Button btnAds;
 18        private System.Windows.Forms.Button btnExit;
 19        private AxSHDocVw.AxWebBrowser awbMain;
 20        private System.ComponentModel.IContainer components;
 21
 22        public frmGetAdLink()
 23        {
 24            //
 25            // Windows 窗体设计器支持所必需的
 26            //
 27            InitializeComponent();
 28
 29            //
 30            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
 31            //
 32        }

 33
 34        /// <summary>
 35        /// 清理所有正在使用的资源。
 36        /// </summary>

 37        protected override void Dispose( bool disposing )
 38        {
 39            if( disposing )
 40            {
 41                if(components != null)
 42                {
 43                    components.Dispose();
 44                }

 45            }

 46            base.Dispose( disposing );
 47        }

 48
 49        #region Windows 窗体设计器生成的代码
 50        /// <summary>
 51        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
 52        /// 此方法的内容。
 53        /// </summary>

 54        private void InitializeComponent()
 55        {
 56            this.components = new System.ComponentModel.Container();
 57            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmGetAdLink));
 58            this.timRefresh = new System.Windows.Forms.Timer(this.components);
 59            this.panBottom = new System.Windows.Forms.Panel();
 60            this.btnLink = new System.Windows.Forms.Button();
 61            this.btnAds = new System.Windows.Forms.Button();
 62            this.btnExit = new System.Windows.Forms.Button();
 63            this.awbMain = new AxSHDocVw.AxWebBrowser();
 64            this.panBottom.SuspendLayout();
 65            ((System.ComponentModel.ISupportInitialize)(this.awbMain)).BeginInit();
 66            this.SuspendLayout();
 67            // 
 68            // timRefresh
 69            // 
 70            this.timRefresh.Interval = 20000;
 71            // 
 72            // panBottom
 73            // 
 74            this.panBottom.Controls.Add(this.btnLink);
 75            this.panBottom.Controls.Add(this.btnAds);
 76            this.panBottom.Controls.Add(this.btnExit);
 77            this.panBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
 78            this.panBottom.Location = new System.Drawing.Point(0328);
 79            this.panBottom.Name = "panBottom";
 80            this.panBottom.Size = new System.Drawing.Size(62656);
 81            this.panBottom.TabIndex = 1;
 82            // 
 83            // btnLink
 84            // 
 85            this.btnLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
 86            this.btnLink.Enabled = false;
 87            this.btnLink.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
 88            this.btnLink.Location = new System.Drawing.Point(45016);
 89            this.btnLink.Name = "btnLink";
 90            this.btnLink.TabIndex = 9;
 91            this.btnLink.Text = "Link(&L)";
 92            this.btnLink.Click += new System.EventHandler(this.btnLink_Click);
 93            // 
 94            // btnAds
 95            // 
 96            this.btnAds.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
 97            this.btnAds.Enabled = false;
 98            this.btnAds.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
 99            this.btnAds.Location = new System.Drawing.Point(36216);
100            this.btnAds.Name = "btnAds";
101            this.btnAds.TabIndex = 8;
102            this.btnAds.Text = "Ads(&A)";
103            this.btnAds.Click += new System.EventHandler(this.btnAds_Click);
104            // 
105            // btnExit
106            // 
107            this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
108            this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
109            this.btnExit.Location = new System.Drawing.Point(53816);
110            this.btnExit.Name = "btnExit";
111            this.btnExit.TabIndex = 4;
112            this.btnExit.Text = "退出(&X)";
113            this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
114            // 
115            // awbMain
116            // 
117            this.awbMain.Dock = System.Windows.Forms.DockStyle.Fill;
118            this.awbMain.Enabled = true;
119            this.awbMain.Location = new System.Drawing.Point(00);
120            this.awbMain.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("awbMain.OcxState")));
121            this.awbMain.Size = new System.Drawing.Size(626328);
122            this.awbMain.TabIndex = 2;
123            this.awbMain.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.awbMain_DocumentComplete);
124            // 
125            // frmGetAdLink
126            // 
127            this.AutoScaleBaseSize = new System.Drawing.Size(614);
128            this.BackColor = System.Drawing.SystemColors.Control;
129            this.ClientSize = new System.Drawing.Size(626384);
130            this.Controls.Add(this.awbMain);
131            this.Controls.Add(this.panBottom);
132            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
133            this.Name = "frmGetAdLink";
134            this.Text = "mshtml获得广告Google Adsense路径";
135            this.Load += new System.EventHandler(this.frmGetAdLink_Load);
136            this.panBottom.ResumeLayout(false);
137            ((System.ComponentModel.ISupportInitialize)(this.awbMain)).EndInit();
138            this.ResumeLayout(false);
139
140        }

141        #endregion

142
143        /// <summary>
144        /// 应用程序的主入口点。
145        /// </summary>

146        [STAThread]
147        static void Main() 
148        {
149            Application.Run(new frmGetAdLink());
150        }

151
152
153        private mshtml.IHTMLDocument2 doc = null;
154
155        private mshtml.IHTMLWindow2 win = null;
156
157        private int intDCCount = 0;
158
159        private void frmGetAdLink_Load(object sender, System.EventArgs e)
160        {
161            object url = null;
162            
163            url = "http://www.cnblogs.com/waxdoll";
164
165            object r = System.Reflection.Missing.Value;
166
167            this.awbMain.Navigate2(ref url,ref r,ref r,ref r,ref r);
168        }

169
170
171        private void awbMain_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
172        {
173            this.doc = (mshtml.IHTMLDocument2)this.awbMain.Document;
174
175            this.win = this.doc.parentWindow;
176
177            if (this.intDCCount == 0)
178                this.btnAds.Enabled = true;
179
180            this.intDCCount ++;
181        }

182
183        /// <summary>
184        /// 在浏览器中显示Google Adsense的广告
185        /// </summary>
186        /// <param name="sender"></param>
187        /// <param name="e"></param>

188        private void btnAds_Click(object sender, System.EventArgs e)
189        {
190
191            this.btnAds.Enabled = false;
192
193            mshtml.IHTMLIFrameElement eleIframe = (mshtml.IHTMLIFrameElement)this.doc.all.item("google_ads_frame"null);
194
195            object url = null;
196            
197            url = ((mshtml.HTMLIFrameClass)eleIframe).src;
198
199            object r = System.Reflection.Missing.Value;
200
201            this.awbMain.Navigate2(ref url, ref r, ref r, ref r, ref r);
202
203            this.btnLink.Enabled = true;
204
205            eleIframe = null;
206        }

207
208        /// <summary>
209        /// 弹出对话框显示广告中的地址
210        /// </summary>
211        /// <param name="sender"></param>
212        /// <param name="e"></param>

213        private void btnLink_Click(object sender, System.EventArgs e)
214        {
215            mshtml.IHTMLElement2 eleLink = (mshtml.IHTMLElement2)this.doc.all.item("aw0"null);
216
217
218            System.Windows.Forms.MessageBox.Show(((mshtml.HTMLAnchorElementClass)eleLink).href);
219        }

220
221
222        private void btnExit_Click(object sender, System.EventArgs e)
223        {
224            this.Dispose();
225        }

226
227    }

228}

229








Life is like a boat, and I'm at sea.

posted @ 2005-07-11 11:57 蜡人张 阅读(2663) 评论(21)  编辑 收藏 所属分类: C#COM & COM+Google AdsenseToys

  回复  引用  查看    
#1楼[楼主]2005-07-12 14:36 | 蜡人张      
经测试,在btnLink_Click中使用System.Diagnostics.Process.Start(((mshtml.HTMLAnchorElementClass)eleLink).href);可以形成有效点击,不过不可以做坏事哦,呵呵……
  回复  引用    
#2楼2005-08-22 23:05 | david[未注册用户]
除非程序运行在每个访问者的客户端,否则还是不能作弊的。

  回复  引用    
#3楼2005-08-23 15:05 | 蜡人张
作弊根本就是不现实的,Goolge是很难被欺骗的。
  回复  引用    
#4楼2005-09-09 09:58 | 阿良.NET[未注册用户]
不行的,我点击了后提示未将对象引用设置到对象的实例。
  回复  引用    
#5楼2005-09-09 10:05 | 阿良.NET[未注册用户]
你看的站http://chjl.cn,这样基本上100IP每天的流量有办法赚得到钱的吗?
Google Adsense计划要求放了他的广告后就不许放其他的广告。像我的小站这样是放很多的站的广告还是只放google adsense 的广告好?
请指教。
另外,我可以转帖你这篇文章吗?谢谢。

  回复  引用  查看    
#6楼[楼主]2005-09-09 16:07 | 蜡人张      
@阿良.NET:

1、需要的话,我可以把程序发给你。提醒你一下,通过作弊赚钱是不可能的;

2、100IP/d的流量是赚不到钱的。

3、Google Adsense只要求不放可能与它的广告形成竞争的广告。

BTW: 欢迎转载!

  回复  引用    
#7楼2005-09-09 16:42 | 阿良.NET[未注册用户]
谢谢 蜡人张 的支持啊!我真的好感动,你是在网上我遇到的第二个有点感动的人,第一个是笨笨蜗牛

我也知道100IP/d是不可能赚钱的,但也想试试。因为有了你的支持,以后可能会增加。就是想一年看看能不能付一次就满足了。

我上面有当当的广告,百度的搜索框,亿流,还有网易的搜索。
以你的经验,这几个哪个和Google同时放会被Kill掉?

  回复  引用    
#8楼2005-09-09 16:52 | 蜡人张
@阿良.NET:

呵呵,不客气

百度和网易的搜索可能比较危险,因为Google也有基于搜索的Adsense。但是,还没有听说过有因为这样被Kill掉的帐户。

现在在出差,回去给你发个Overture Bid Tool,在流量稳定、点击率稳定的情况下只有提高关键字的价格啦,呵呵……

  回复  引用    
#9楼2005-09-09 21:41 | 阿良.NET[未注册用户]
好的,请发chjlcn@126.com?subject=CJL(email主题需以CJL开始才能收到。)
本页的代码也发过来。谢谢。

  回复  引用    
#10楼2005-09-14 01:22 | waxdoll
@阿良.NET:
邮件已发。

  回复  引用    
#11楼2005-10-04 21:28 | 小胖虫[未注册用户]
发一份给我吧。
谢谢。
xptong@163.com

  回复  引用  查看    
#12楼[楼主]2005-10-05 01:51 | 蜡人张      
@小胖虫:

十一在家里,恰好邮箱"已发送"文件夹中有一份,已经转发给你了。

  回复  引用    
#13楼2005-10-21 06:18 | sonda[未注册用户]
发一份给我吧。
谢谢。
sonda@163.com

非常谢谢!

  回复  引用    
#14楼2005-11-04 10:20 | David yan[未注册用户]
能不能发我一份.我最近正在做WebBrowser这方面的开发.
  回复  引用    
#15楼2005-11-04 10:21 | David yan [未注册用户]
汗,我忘记留MAIL了:weidong35@hotmail.com
  回复  引用    
#16楼2005-11-07 18:36 | jlt[未注册用户]
希望与你交朋友 我得qq 58135371
  回复  引用    
#17楼2006-05-12 19:13 | 明皓[未注册用户]
呵呵,你觉得可以实现吗??有效点击????

这么容易就做弊了的话,GG岂不是要赔不少.

如果我在服务端加一个ISAPI

我可以得到请求此FRAME页面的REFERER.

还可以得到点击广告后..的REFERER.

你现在的广告页是要重新载入一次的,这不是一下就露陷了????

  回复  引用    
#18楼2006-12-03 11:58 | 阿学[未注册用户]
@蜡人张

想知道怎么提高 GGAD 的关键词价格!!!
Overture Bid Tool 那里有下载?
希望交流 QQ 29405634 whjtoby@sohu.com

  回复  引用    
#19楼2008-06-13 03:05 | 求学者1981[未注册用户]
你好,请问能否把源码给我一份,正做这方面的事情,一直找不到资料!
我Email 6671411@qq.com

  回复  引用    
#20楼2008-07-29 08:42 | 手震[未注册用户]
你直接用Navigate 打开Google的连接当然容易获得这些内容了.
但如果你在正常页面里访问Google生成的IFRAME里的元素试试!

  回复  引用  查看    
#21楼[楼主]2008-07-30 20:08 | 蜡人张      
@手震
你没有仔细看……




发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 190439




相关文章:

相关链接: