首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Selenium VBA将数据提取到Excel中

Selenium VBA将数据提取到Excel中
EN

Stack Overflow用户
提问于 2020-05-08 20:06:44
回答 1查看 277关注 0票数 0

先生,我得到的问题,以获得数据到excel,我有一些selenium代码,以获得数据从URL最大分页号。以超越一切。

here is url

代码语言:javascript
运行
复制
Public Sub URL_Max_Page()
Dim driver As New ChromeDriver
Dim URL As String

'open the page with the URL
    URL = "https://www.justdial.com/Rajkot/Software-Companies/page-60"

driver.Get [URL]

'get maximum page number in to excel

MX = driver.FindElementsById("paginationlastPageNum").Text

   ActiveSheet.Range("A7") = MX
   driver.Quit

End Sub

我收到一些错误..我不知道如何让我的代码正常工作

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-08 20:47:30

不确定,但试试这个

代码语言:javascript
运行
复制
Public Sub URL_Max_Page()
    Dim driver As New ChromeDriver, aScriptParts, mx, sURL As String, sResp As String, sScriptPart As String, i As Long
    sURL = "https://www.justdial.com/Rajkot/Software-Companies/page-60"
    With driver
        .Get [sURL]
        sResp = .PageSource
        aScriptParts = Split(sResp, "<script", , vbTextCompare)

        For i = LBound(aScriptParts) + 1 To UBound(aScriptParts)
            sScriptPart = Split(aScriptParts(i), "</script", , vbTextCompare)(0)
            If InStr(sScriptPart, "paginationPageNum") Then
                mx = Split(Split(sScriptPart, "paginationPageNum = ")(1), ";")(0)
                Exit For
            End If
        Next i
        Debug.Print mx
        .Quit
    End With
End Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61678803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档