如何从网站上的第10行获取数据 [英] How do I get data from 10th line, in a website

查看:61
本文介绍了如何从网站上的第10行获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var ele = (
                from T in webBrowser1.Document.GetElementsByTagName("div").Cast<HtmlElement>()
                where T.GetAttribute("classname") == "ball ball-1"
                select T).FirstOrDefault();





嘿,我试图用一个ui制作一个简单的csgodouble bot。我想从名为csgodouble的网站获取一些数据。但是我遇到了问题。



div data-rollid =310835class =ball ball-1> 1 / div





html元素。

但是有10条线条看起来像那样,非常小的不同,它们每分钟都会改变或者。你怎么才能从第10行获得数据?

试图使用上面的代码,但它会读取所有第10行。



我知道xpath,只会让你从第10行获取数据。但不知道如何使用它,在我的应用程序中获取数据。我在visual studio中使用windowsapplication项目。

// * [@ id =past] / div [10] xpath代码。



i已经在谷歌上搜索了一些帮助,似乎无法找到任何东西!



如果知道如何解决它,并会有所帮助。请说出你做了什么,为什么。所以我可以更好地理解c#和代码。









更新问题d 5 / 18-2016 - 9:51





Hey, im trying to make a simple csgodouble bot, with a ui. I want to get some data from a website called, csgodouble. but i have came into a problem.

div data-rollid="310835" class="ball ball-1">1 /div


html element.
but there are 10 lines there look like that, with very small different, and they change each minute or so. how can you only get the data from the 10th line??
have tried to use the code above, but it will read all the 10th line.

i know xpath, will provide you to only get data from 10th line. but have no clue how to use it, to get that data in my application. i use the windowsapplication project in visual studio.
//*[@id="past"]/div[10] xpath code.

i have searched all over google for help, cant seem to find anything!

If have know how to fix it, and will help. please say what you have done, and why. so i can get a better understanding of c# and code in general.




update to the question d 5/18-2016 - 9:51

http://imgur.com/a/7VdHB

Hey here can you see my code, and the source code from csgodouble.

I have tried everything to get the 10th line information.
have tried ElementAtOrDefault(9); at 10, instead of 9.. but doesnt seem to work
the data-rollid change every time a new number comes in.

i want to get output, if it was red, black or green there won.
the last line in the source code, is color that won
ball ball-1 = red
ball ball-8 = black
ball ball-0 = green</pre>





我是什么尝试过:





What I have tried:

var ele = (
                from T in webBrowser1.Document.GetElementsByTagName("div").Cast<HtmlElement>()
                where T.GetAttribute("classname") == "ball ball-1[10]"
                select T).FirstOrDefault();





和其他更简单的代码,但我删除了它们。尝试了一点xpath。但不是很多。



And other simpler code, but i have delete them. tried a little bit of xpath. but not much.

推荐答案

如果你想从序列中获取第10个项目,用<替换 FirstOrDefault a href =https://msdn.microsoft.com/en-us/library/bb494386(v=vs.100).aspx> ElementAtOrDefault [ ^ ]:

If you want to get the 10th item from the sequence, replace FirstOrDefault with ElementAtOrDefault[^]:
var parent = webBrowser1.Document.GetElementById("past");
if (parent != null)
{
    var balls = from b in parent.GetElementsByTagName("div").Cast<HtmlElement>()
                where b.GetAttribute("classname").StartsWith("ball ball-")
                select b;
    
    var theBall = balls.ElementAtOrDefault(9);
    if (theBall != null)
    {
        // Do something with the element here...
    }
}



NB:索引从零开始,因此第10个元素位于索引9处。


NB: The index is zero-based, so the 10th element is at index 9.


这篇关于如何从网站上的第10行获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆