2
我正在爲我的女朋友編寫一個程序,允許她打開該程序,它會自動從她的星座網站收集她的報價,並顯示該行文本文本框。在VB.Net中使用HtmlAgilityPack從網站獲取文本
至於我現在的情況,它基本上顯示整個網站的HTML,這不是我想要的。這是我需要抓住的HTML線。
<div class="fontdef1" style="padding-right:10px;" id="textline">
"You might have the desire for travel, perhaps to visit a friend who lives far away, Gemini. You may actually set the wheels in motion to make it happen. Social events could take up your time this evening, and you could meet some interesting people. A friend might need a sympathetic ear. Today you're especially sensitive to others, so be prepared to hear a sad story. Otherwise, your day should go well.
</div>
我到目前爲止的代碼是。
Imports System.Net
Imports System.IO
Imports HtmlAgilityPack
Public Class Form1
Private Function getHTML(ByVal Address As String) As String
Dim rt As String = ""
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
wRequest = WebRequest.Create(Address)
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
Return rt
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Text = Date.Now.ToString("MM/dd/yyyy")
TextBox1.Text = getHTML("http://my.horoscope.com/astrology/free-daily-horoscope-gemini.html")
End Sub
End Class
謝謝你的幫助,我可以得到。我現在真的不知道該怎麼辦。已經3天沒有進展了。
好吧我帶你的建議,並試圖將你從控制檯轉換爲IO,以便它將輸出到我的TextBox1。 我改變了'Console.WriteLine(div.InnerText.Trim())'來 '昏暗完成的String =(div.InnerText.Trim())' 問題是現在,我不知道怎麼拉字符串「完成」到我的私人小組用於TextBox1。我曾嘗試調用Main,認爲字符串會隨之而來,但我想不是這種情況。 有什麼建議嗎?謝謝 – RockGuitarist1
@ RockGuitarist1'TextBox1.Text = finish'? – har07
我收到錯誤,說'finish'沒有聲明。好像我不能將它從'Public Sub Main()'移動到'Private Sub Form1_Load'。 – RockGuitarist1