網頁抓資料-求解

mars


Imports System.Web
Imports System.Net.Sockets 'HttpWebRequest、HttpWebResponse類別
Imports System.Net
Imports System.IO 'StreamReader類別


System.Net.ServicePointManager.DefaultConnectionLimit = 50
Dim request As HttpWebRequest
request = WebRequest.Create("http://www.cmegroup.com/CmeWS/mvc/Settlements/Futures/Settlements/58/FUT?strategy=DEFAULT&tradeDate=05/18/2021")
Dim mResponse As HttpWebResponse = request.GetResponse() <===到這就作業逾時

Dim sr As New StreamReader(mResponse.GetResponseStream, System.Text.Encoding.GetEncoding("UTF-8"))
Dim strContent = sr.ReadToEnd()
Dim strContent = sr.ReadToEnd()
sr.Close()
request = Nothing
mResponse = Nothing
MsgBox(strContent)



有試著加這些東西>但沒用一樣逾時
request.Method = "GET"
request.Host = "www.cmegroup.com"
request.KeepAlive = True
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"

request.Headers.Set("Accept-Encoding", "gzip, deflate, br")
request.Headers.Set("Accept-Language", "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7")
request.Headers.Set("Cache-Control", "max-age=0")
request.Headers.Set("sec-ch-ua", " ""Not A;Brand"";v=""99"", ""Chromium"";v=""90"", ""Google Chrome"";v=""90""")
request.Headers.Set("sec-ch-ua-mobile", "?0")
request.Headers.Set("Sec-Fetch-Dest", "document")
request.Headers.Set("Sec-Fetch-Mode", "navigate")
request.Headers.Set("Sec-Fetch-Site", "none")
request.Headers.Set("Sec-Fetch-User", "?1")
request.Headers.Set("Upgrade-Insecure-Requests", "1")
request.Timeout = 100000





mars
已解 !!!
新增request.Headers.Set("X-Requested-With", "XMLHttpRequest")
回到頂部