如何让vb.net从vb浏览器添加特定div中的所有链接? [英] How do I get vb.net to add all links within a particular div from vb browser?

查看:112
本文介绍了如何让vb.net从vb浏览器添加特定div中的所有链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让vb.net从vb浏览器中添加特定div中的所有链接?



我正试图从div获取所有链接class linksmain。



例如



How do I get vb.net to add all links within a particular div from vb browser?

I''m trying to get all links from the div class linksmain.

E.g.

<div class="linksmain">
<a href="http://www.image1.com">Image</a>
<a href="http://www.image2.com">Image</a>
<a href="http://www.image3.com">Image</a>
</div>







到目前为止我已经得到了这个..



代码:






So far I''ve got this..

Code:

Dim web As New WebBrowser

If web.ReadyState = WebBrowserReadyState.Complete Then
    Dim allelements As HtmlElementCollection = web.Document.All

    For Each webpageelement As HtmlElement In allelements

        ListBox1.Items.Add(webpageelement.GetAttribute("class"))

    Next
End If

推荐答案

那客户端的东西 - 你会的使用javascript。这是一个javascript函数,它将返回一个数组,其中包含所选div中所有元素(具有ID)的ID。你必须列举它们并决定你需要使用哪些孩子。这意味着你要找的所有物品当然都必须有ID。



That''s client side stuff - you would use javascript for that. Here''s a javascript function that will return an array containing the IDs of all the elements (that have IDs) in the chosen div. You''ll have to enumerate them and decide which children you need to use. This means that all the items you are looking for must have IDs, of course.

function GetAllChildrenIn(parentElement) {
         var children = new Array();
         var numFound = 0;
         try {
             var obj = document.getElementById(parentElement);
             var numChildren = obj.childNodes.length;
         } catch (e) {
             alert('Error setting vars. (' + e.Message + ')'); }

         try {
             for (var count = 0; count < numChildren; count++) {
                 if (obj.childNodes[count].id) {
                     children[numFound] = obj.childNodes[count].id;
                     numFound++;
                 }
             }
         } catch (e) { alert('Error enumerating children. (' + e.Message + ')'); }

         return children;
     }


这篇关于如何让vb.net从vb浏览器添加特定div中的所有链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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