问题情况:关于VB WINSOCK提取网页源文件不成功,请问该怎么解决?

'添加Command1 Winsock1 Richtextbox1 Text1 Text2 
'RichTextBox1.ScrollBars = rtfBoth 
'在Text1输入域名, Text2输入网址, 点击 Command1 

Option Explicit 
Dim myall$, aa$, jj&, kk&, strCommand$, strWebPage$ 
Private Sub Form_Load() 
 Winsock1.Protocol = 0 
 Winsock1.RemotePort = 80 
 Text1.Text = "BBS.CHIAN95.NET" 
 Text2.Text = "BBS.CHIAN95.NET" 
End Sub 

Private Sub Command1_Click() 
 Winsock1.Close 
 RichTextBox1.Text = "" 
 Winsock1.RemoteHost = Text1.Text 
 strWebPage = Text2.Text 
 Winsock1.Connect '开始提取数据 
End Sub 

Private Sub Winsock1_Connect() 
 strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf 
 strCommand = strCommand + "Accept: */*" + vbCrLf 
 strCommand = strCommand + "Accept: text/html" + vbCrLf 
 strCommand = strCommand + vbCrLf 
 Winsock1.SendData strCommand '发送命令 
End Sub 

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) 
 '开始下载,收到数据时,发生DataarriVal事件 
 On Error Resume Next 
 Dim webData As String 
 Winsock1.GetData webData, vbString 
 RichTextBox1.Text = RichTextBox1.Text & webData '取得相关的网页文件 
End Sub
其它慢了,WINSOCK速度快些,我是批量提取的

凤凰求蛊
浏览 560回答 2
2回答

慕哥9229398

Private Sub Command1_Click()Set xmlHTTP1 = CreateObject("Microsoft.XMLHTTP")xmlHTTP1.Open "get", "http://www.baidu.com", TruexmlHTTP1.sendWhile xmlHTTP1.readyState <> 4DoEventsWendText1.Text = xmlHTTP1.responseTextSet xmlHTTP1 = NothingEnd Sub

蛊毒传说

Set xmlhttp = CreateObject("Microsoft.XMLHTTP")xmlhttp.Open "post", (url_t), True '用GET方式,打开个别网页,死机无影应xmlhttp.SendDo Until xmlhttp.ReadyState = 4 '这里阻塞前面的,确保登陆成功之后再取页面,你可以将此Do取消了试一次。DoEventsIf 15 < DateDiff("s", time_begin, Now) Or xmlhttp.ReadyState > 4 Then '30秒钟打不开网页,或返回状态有误大于4则跳过Err_b = TrueGoTo url_endEnd IfLoopDoEvents'rtb1.Text = bytes2BSTR(xmlhttp.ResponseBody)'可用但速度慢rtb1.Text = StrConv(xmlhttp.ResponseBody, vbUnicode)'Set xmlhttp = NothingRTB1为一文本框
打开App,查看更多内容
随时随地看视频慕课网APP