本帖最后由 loa123 于 2024-7-5 22:18 编辑
[Visual Basic] 纯文本查看 复制代码 ' 创建XMLHTTP对象
Dim xml As Object
Set xml = CreateObject("MSXML2.XMLHTTP")
' 构造URL
Dim playID As String
playID = 192985
Dim url As String
url = "https://sofifa.com/player/" & playID & "/240045/"
' 设置请求头
xml.Open "GET", url, False
xml.setRequestHeader "User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1"
' 发送请求
xml.send
Dim responseText As String
responseText = xml.responseText ' 捕获完整的响应文本' 检查HTTP请求是否成功
If xml.Status <> 200 Then
MsgBox "请求失败,状态码:" & xml.Status & ". 响应文本:" & vbCrLf & responseText & ". 请检查playID: " & playID
' 清理资源
Set xml = Nothing
Exit Sub
End If
使用浏览器访问https://sofifa.com/player/192985/240045/没问题,但是使用VBA就会403访问错误。。。有什么办法解决?? |