【问题标题】:Using WatIN to determine website's position in google使用 WatIN 确定网站在谷歌中的位置
【发布时间】:2009-04-20 09:53:34
【问题描述】:

我正在使用 WatIn - 并且拥有当前脚本:

IE ie = new IE("http://www.google.co.il");
ie.TextField(Find.ByName("q")).TypeText(mykeyword);
ie.Button(Find.ByName("btnG")).Click();

现在我想以某种方式了解我的网站所处的位置。

我知道 google 将网站的网址包装在他们的页面中(我正在解析 google.co.il):

<span dir=ltr>www.website.co.il/</span>

我知道它应该是这样的: 即.Span(Find.XXX))

我是 WatIN 的新手,如果有任何帮助,我将不胜感激。

提前致谢。

【问题讨论】:

    标签: c# watin


    【解决方案1】:

    自己找到了解决方案:

                using (IE ie = new IE("http://www.google.co.il"))
                {
                    ie.TextField(Find.ByName("q")).TypeText(keyword);
                    ie.Button(Find.ByName("btnG")).Click();
                    int position = 1;
                    label1.Text = "";
                    foreach (Span span in ie.Spans)
                    {
                        if (span.OuterHtml.ToLower().StartsWith("<span dir=ltr>"))
                        {
                            label1.Text += position.ToString() + ": " + span.InnerHtml + "\n";
                            position++;
                        }
                    }
                }
    

    【讨论】:

    • 当您在 Spans 集合上使用 Filter 时,您甚至可以像这样删除 if:foreach(Span span in ie.Spans.Filter(Find.By("dir", "ltr"))
    猜你喜欢
    • 2017-09-22
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 2012-09-05
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    • 2013-08-05
    相关资源
    最近更新 更多