TPYI123
2021-07-27 10:11
采纳率: 75%
浏览 176

求 vb同时爬取网页数据的代码!!

多个timer 同时进行网页数据爬取应该怎么弄呢?

url4 = "https://query1.finance.yahoo.com/v8/finance/chart/CLNN?symbol=CLNN&period1=1626960600&period2=1627047000&useYfid=true&interval=1m&includePrePost=true&events=div%7Csplit%7Cearn&lang=en-US&region=US&crumb=buQ55SZKDGy&corsDomain=finance.yahoo.com"
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", url4, True
.Send
While .ReadyState <> 4
DoEvents
Wend
shuju = (.responsetext)
End With

  • 点赞
  • 收藏

2条回答 默认 最新

  • soar3033 2021-07-27 10:20
    已采纳
    Class spd'定义爬虫类
    Public url as String'定义url
    Sub sp()'定义方法
    With CreateObject("Microsoft.XMLHTTP")
    .Open "GET", url4, True
    .Send
    While .ReadyState <> 4
    DoEvents
    Wend
    shuju = (.responsetext)
    End With
    End Sub
    End Class
    Dim Tasks1 As New spd()'实例化爬虫类
    Dim Tasks2 As New spd()'实例化爬虫类
    Dim Tasks3 As New spd()'实例化爬虫类
    '更改每个爬虫类内要爬取的url地址
    Tasks1.url="https://query1.finance.yahoo.com/v8/finance/chart/CLNN?symbol=CLNN&period1=1626960600&period2=1627047000&useYfid=true&interval=1m&includePrePost=true&events=div%7Csplit%7Cearn&lang=en-US&region=US&crumb=buQ55SZKDGy&corsDomain=finance.yahoo.com"
    Tasks2.url="https://query1.finance.yahoo.com/v8/finance/chart/CLNN?symbol=CLNN&period1=1626960600&period2=1627047000&useYfid=true&interval=1m&includePrePost=true&events=div%7Csplit%7Cearn&lang=en-US&region=US&crumb=buQ55SZKDGy&corsDomain=finance.yahoo.com"
    Tasks3.url="https://query1.finance.yahoo.com/v8/finance/chart/CLNN?symbol=CLNN&period1=1626960600&period2=1627047000&useYfid=true&interval=1m&includePrePost=true&events=div%7Csplit%7Cearn&lang=en-US&region=US&crumb=buQ55SZKDGy&corsDomain=finance.yahoo.com"
    '创建线程
    Dim Thread1 As New System.Threading.Thread( _
           AddressOf Tasks1.sp)
    Dim Thread2 As New System.Threading.Thread( _
           AddressOf Tasks2.sp)
    Dim Thread3 As New System.Threading.Thread( _
           AddressOf Tasks3.sp)
    '运行线程
    Thread1.Start() ' 启动新线程。
       Thread1.Join() ' 等待线程 1 运行结束。
    Thread2.Start() ' 启动新线程。
       Thread2.Join() ' 等待线程 1 运行结束。
    Thread3.Start() ' 启动新线程。
       Thread3.Join() ' 等待线程 1 运行结束。
    
    点赞 打赏 评论
  • weixin_52754092 2021-07-30 15:49

    你们为什么还在学vb,这不是很久以前的知识了

    点赞 打赏 评论

相关推荐 更多相似问题