我一直在研究如何做到这一点,不幸的是找不到任何答案。我想找到特定网页的确切大小,或者如果不可能,则查找特定网页源代码的字数/字符数。
我这样做是为了找到存在的网站页面,而不是通过字符串,If语句和For循环不存在的页面,通过测试“/”之后的每个可能的数字组合网站前面的网址,并且不包括某个尺寸以下的网页,这些网页会加载404错误,或者不存在错误,这意味着唯一生成的网页将是那些存在的网页。我正在寻找的这些页面没有链接到它们,也无法在搜索引擎上找到。找到它们的唯一方法是在“/”之后键入确切的数字,例如:(http://website.com/123456789)也许这个即兴的暴力方法会找到我正在寻找的页面。谢谢!
答案 0 :(得分:0)
Dim URL As String
'Requesting for file details
Dim req As System.Net.WebRequest = System.Net.HttpWebRequest.Create(URL)
req.Method = "HEAD"
'Retriving the response
Dim resp As System.Net.WebResponse = req.GetResponse()
Dim ContentLength As Long = 0
Dim result As Long
'Finding the file size
If Long.TryParse(resp.Headers.Get("Content-Length"), ContentLength) Then
Dim File_Size As String
If ContentLength >= 1073741824 Then
result = ContentLength / 1073741824
ElseIf ContentLength >= 1048576 Then
result = ContentLength / 1048576
Else
result = ContentLength / 1024
End If
File_Size = result.ToString("0.00")
End If
检查404页
Private Function RemoteFileOk(ByVal Url As String) As Boolean
Using client As New HttpClient,
responseTask As Task(Of HttpResponseMessage) = client.GetAsync(Url, HttpCompletionOption.ResponseHeadersRead)
responseTask.Wait()
Using response As HttpResponseMessage = responseTask.Result
Return response.IsSuccessStatusCode
End Using
End Using
End Function