2010-10-20 22 views

回答

0

我不知道它是否在WebBroswer。我們做broswer(IE/FF /等)窗口滾動到一些文字用下面的代碼:

//source code of http://www.sample.com/sample.html 
<html> 
... 
<span name="aim">KeyWord</span> 
... 
</html> 

如果我想在窗口滾動到「關鍵字」,只需訪問http://www.sample.com/sample.html#aim

使用string document = myWebBrowser.DocumentText獲取頁面的源代碼,並搜索字符串中的文本,獲取其節點名稱,然後使用#進行導航。

+0

實際上問題沒有滾動到特定的節點;已經完成。找到與搜索查詢匹配的文本的選擇是主要問題。 – 2010-10-20 18:55:19

+0

@Mostafa Mahdieh:看我的編輯。 – 2010-10-21 02:12:15

+0

我必須在這裏添加一些細節...在文本中搜索會得到字符串中的一個索引。找到包含該字符串的節點並不是那麼簡單:匹配的文本可能是合併到節點中的多個文本節點的結果。 – 2010-10-22 09:40:29

1

你可以試試這個代碼:

webBrowser1.Select(); SendKeys.Send(「^ f」);

0

看到這個,如果有幫助:

string PageSource = null; 
PageSource = WebBrowser1.Document.Body.InnerHtml(); 
if (Strings.InStr(PageSource, stringtoFind) > 0) { 
    ...insert an Anchor tag here and then use 
    WebBrowser1.Navigate to go to the the new URL with the #Anchor tag 
} else { 
...whatever else 
} 
0

的一種方式......

使用Ctrl + F鍵來調用Find,原產於WebBrowser控件?