|
各位老师好,
想练习网抓数据,但是使用如下代码抓出的和在网页查看的HTM数据不一样呢,求指教
- Sub main1()
- Dim strText As String
- With CreateObject("WinHttp.WinHttpRequest.5.1")
- .Open "GET", "https://www.baidu.com/s?wd=你好&ie=UTF-8", False
-
- .setRequestHeader "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"""
- ' .setRequestHeader "Accept-Encoding", "gzip , deflate, br"
- .setRequestHeader "Accept-Language", "zh-CN,zh;q=0.9"
- .setRequestHeader "Cache-Control", "Max -age = 0"
- .setRequestHeader "Connection", "keep -alive"
- .setRequestHeader "Cookie", "BIDUPSID=888C9534F545E23EFA69539A181351D1; PSTM=1651968877; BAIDUID=21C54EDE086C240D41B53A411348F8E6:FG=1;"
- .setRequestHeader "Host", "www.baidu.com"
- .setRequestHeader "sec-ch-ua", """ Not A;Brand"";v=""99"",""Chromium"";v=""99"",""google Chrome"";v=""99"""
- .setRequestHeader "Sec-ch-ua-mobile", "?0"
- .setRequestHeader "sec-ch-ua-platform", """Windows"""
- .setRequestHeader "Sec-Fetch-Dest", "document"
- .setRequestHeader "Sec-etch-Mode", "navigate"
- .setRequestHeader "Sec-Fetch-Site", "same-site"
- .setRequestHeader "Sec-Fetch-User", "?1"
- .setRequestHeader "Upgrade-Insecure-Requests", "1"
- .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
- .send
- Debug.Print .responseText
- End With
- End Sub
复制代码
|
|