【发布时间】:2015-07-21 01:41:20
【问题描述】:
我正在为我的女朋友编写一个程序,它允许她打开程序,它会自动从星座网站收集她的一句话,并在 TextBox 中显示该行文本。
就我现在所拥有的而言,它基本上以 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天了,没有任何进展。
【问题讨论】: