2011-08-14 56 views
-3

好吧所以這裏是HTMLVB.NET抓取文本

<li class="comment " 
     data-author-viewing="False" 
     data-id="FqTXOQTcyYaaGaT51z1St1pYFZW5ycutLsrLpoFIJow" 
     data-score="0" 
     data-author="pervychika666"> 

     <div class="comment-body"> 

    <div class="content-container"> 
    <div class="content"> 
     <div class="author "> 
     <a href="/user/pervychika666" title="pervychika666">pervychika666</a> 
     </div> 


     <div class="comment-text" dir="ltr"> 
      <p>Look at the female audience, they were all giggling and excited, a lot of women got excited with gay erotica, I admit I&#39;m one of them.</p> 

     </div> 
    </div> 


    <div class="metadata"> 
<span class="comment-actions comment-extra-actions"><a class="comment-action" data-action="flag">Flag</a><span class="comment-action-block"><span class="comment-metadata-separator">&bull;</span><a class="comment-action" data-action="block">Block User</a></span><span class="comment-action-unblock"><span class="comment-metadata-separator">&bull;</span><a class="comment-action" data-action="unblock">Unblock User</a></span><span class="comment-action-remove"><span class="comment-metadata-separator">&bull;</span><a class="comment-action" data-action="remove">Remove</a></span></span> 
     <span class="time"> 
     2 days ago 
     </span> 

<span class="comment-actions"><span class="comment-action-vote-up"><a class="comment-action" data-action="vote-up">Like</a><span class="comment-metadata-separator">&bull;</span></span><span class="comment-action-vote-down"><a class="comment-action" data-action="vote-down">Dislike</a><span class="comment-metadata-separator">&bull;</span></span><a class="comment-action-reply comment-action" data-action="reply">Reply</a></span> 
    </div> 
    </div> 

     </div> 
    </li> 




    <li class="comment " 
     data-author-viewing="False" 
     data-id="FqTXOQTcyYagrOGji01HrGJn0tzIJeY4w1rxok5jrp0" 
     data-score="0" 
     data-author="mykellluvs"> 

     <div class="comment-body"> 

    <div class="content-container"> 
    <div class="content"> 
     <div class="author "> 
     <a href="/user/mykellluvs" title="mykellluvs">mykellluvs</a> 
     </div> 


     <div class="comment-text" dir="ltr"> 
      <p>I love their faces when they pull away from the kiss ;D</p> 

     </div> 
    </div> 

現在在哪兒它像數據,筆者=「mykellluvs」>我希望它搶名字mykellluvs,但這樣做對他們都造成有更多的則是一個數據筆者=」的東西在頁面上,將其粘貼到文本框

我怎麼能做到這一點?

+0

嘗試使用['HTMLAgilityPack'](http://www.codeplex.com/htmlagilitypack)這樣的事情... – Yahia

+0

我忍不住內容上的LOL ....無論如何,你可以用WHILE循環做這個 - 而你的HTML字符串包含'data-author =''從等號開始到下一個「(或者如果你喜歡的話修剪」「)。這不是一個強有力的解決方案,但如果你正在尋找快速和骯髒的,它是要走的路。 –

回答

0

你生成HTML或者你試圖從一些地方比解析HTML? 如果你自己生成這個html,你可能想從datasourc中獲取這個信息即如果你是從別的地方得到它,然後XPath的可能是你最好的選擇 我用HtmlAgilityPack像使用XPath解析HTML,所以

// Targets a specific node 
       HtmlNode someNode = document.DocumentNode.SelectSingleNode("//ul[@class='posts']"); 
       // If there is no node with that class, someNode will be null 
       if (someNode != null) 
       { 
        foreach (var item in someNode.Descendants()) 
        { 
         if (item.Attributes["data-author"] != null) 
         { 
          myval = item.Attributes["data-author"]; 
          // You can now check the value in myval to see if its what you want, 
         }        
        } 
       } 

對不起代碼是在C#中,但它很容易轉換成vb.net。您可以在HtmlAgilityPack的文檔中找到更多信息。

+0

http://pastebin.com/zDM8VgBv看看我轉換的代碼 嗨,我是將它轉換在vb.net中,我得到這個錯誤的錯誤 TYPE htmlnode沒有定義 TYPE「變種」沒有定義 –

+0

以及如何我可以將它粘貼到文本框 –

+0

嗨vb.net不支持var,所以我想你可以使用Dim item作爲HtmlNode請參見http://pastebin.com/tzH6qx7b 你到底想要粘貼什麼文本框? –