나는 그녀가 프로그램을 열 수있는 여자 친구를위한 프로그램을 작성 중이며, Horoscope 웹 사이트에서 자동으로 인용문을 모으고 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 일이 지났습니다.
HtmlAgilityPack을 사용하여 HTML 문서에서 특정 정보를 추출하려면 XPath 또는 LINQ 에 대해 알아보십시오. 이것은 XPath 선택기를 사용하는 콘솔 응용 프로그램 예제입니다.
Imports System
Imports System.Xml
Imports HtmlAgilityPack
Public Module Module1
Public Sub Main()
Dim link As String = "http://my.horoscope.com/astrology/free-daily-horoscope-gemini.html"
'download page from the link into an HtmlDocument'
Dim doc As HtmlDocument = New HtmlWeb().Load(link)
'select <div> having class attribute equals fontdef1'
Dim div As HtmlNode = doc.DocumentNode.SelectSingleNode("//div[@class='fontdef1']")
'if the div is found, print the inner text'
If Not div Is Nothing Then
Console.WriteLine(div.InnerText.Trim())
End If
End Sub
End Module
출력 :
아마도 멀리 떨어진 친구 인 제미 나이 (Gemini)를 방문하기 위해 여행을 원할 수도 있습니다. 실제로 바퀴가 움직 이도록 설정할 수 있습니다. 오늘 저녁에는 사교 모임이 당신의 시간을 소화 할 수 있었고 재미있는 사람들을 만날 수있었습니다. 친구는 동정심이 필요한 사람 일 수 있습니다. 오늘날 당신은 특히 다른 사람들에게 민감합니다. 그래서 슬픈 이야기를들을 준비를하십시오. 그렇지 않으면 하루가 잘되어야합니다.