0
현재 특정 웹 페이지에서 데이터를 가져 오는 응용 프로그램을 개발하고 있습니다.동일한 바늘 사이에 여러 건초 더미가 있음
<needle1>HAYSTACK 1<needle2>
<needle1>HAYSTACK 2<needle2>
<needle1>HAYSTACK 3<needle2>
<needle1>HAYSTACK 4<needle2>
<needle1>HAYSTACK 5<needle2>
그리고 나는 다음과 VB.NET 코드가 있습니다 :
Function GetBetween(ByVal haystack As String, ByVal needle As String, ByVal needle_two As String) As String
Dim istart As Integer = InStr(haystack, needle)
If istart > 0 Then
Dim istop As Integer = InStr(istart, haystack, needle_two)
If istop > 0 Then
Dim value As String = haystack.Substring(istart + Len(needle) - 1, istop - istart - Len(needle))
Return value
End If
End If
Return Nothing
End Function
:
Dim webClient As New System.Net.WebClient
Dim FullPage As String = webClient.DownloadString("PAGE URL HERE")
Dim ExtractedInfo As String = GetBetween(FullPage, "<needle1>", "<needle2>")
GetBetween는 다음과 같은 기능입니다
는이 웹 페이지는 다음과 같은 내용을 가지고 말할 수 있습니다 언급 된 코드를 사용하면 ExtractedInfo는 항상 건초 더미를 가져 오기 때문에 항상 "건초 더미 1"과 같습니다. 발견 된 첫 번째 사건에서부터제 질문은 : 두 번째, 세 번째, 네 번째 등의 항목을 찾기 위해 일종의 배열처럼 ExtractedInfo를 설정하는 방법입니다. 같은
뭔가 : 사전에
ExtractedInfo(1) = HAYSTACK 1
ExtractedInfo(2) = HAYSTACK 2
감사합니다!
안녕하세요! 귀하의 답변에 감사드립니다. 지시 한 것처럼 코드가 변경되었지만 함수를 호출하면이 오류가 발생합니다. 오류 'Public Function GetBetween (haystack As String, needle As) 매개 변수의 인수가 지정되지 않았습니다. 문자열, needle_two String, ByRef ExtractedInfo As System.Collections.Generic.List (Of String)) As System.Collections.Generic.List (Of String) '. 내가 뭘 잘못 했니? – user1298923
마지막 매개 변수로 ExtractedInfo 목록을 전달하지 않습니다. 그러나 편집 된 답변을 확인하십시오. 나는 그것이 당신이 정말로 찾고있는 것이라고 생각합니다. –