как зацикливать, чтобы загрузить отличные от href (когда href был одинаковым для всех файлов) - PullRequest
0 голосов
/ 19 апреля 2019

Таргетинг на скачивание превосходит через href. Тем не менее, не удается загрузить все образцы с циклом (когда ссылки href выглядят одинаково). что может быть в этом случае? после загрузки этих файлов, как сохранить каждый Excel в локальной папке C?

Вот необходимые ссылки HTML href

<td class="tenderlink">
<a href='/Documents/ProcurementDisposal/20190419102042818.xls' 
         target="_blank">View</a></td>

Код:

Sub download()
 'Application.ScreenUpdating = False
    Dim ie As InternetExplorer
    Dim ele As Object

    Set ie = New InternetExplorer
    With ie
        .Visible = True
        .Navigate2 "http://www.nafed-india.com/Home/ProcDispoDetails"

        While .Busy Or .readyState < 4: DoEvents: Wend
    End With
    For Each ele In ie.document.querySelector("a[href^='/Documents/ProcurementDisposal']").Click
        Next ele
End Sub

1 Ответ

0 голосов
/ 20 апреля 2019

Попробуйте что-то вроде этого:

Sub download()

    Dim ie As InternetExplorer
    Dim el As Object, els As Object

    Set ie = New InternetExplorer
    With ie
        .Visible = True
        .Navigate2 "http://www.nafed-india.com/Home/ProcDispoDetails"

        While .Busy Or .readyState < 4: DoEvents: Wend
    End With

    'Note: querySelectorAll unless you only want one element
    Set els = ie.document.querySelectorAll("a[href^='/Documents/ProcurementDisposal']")
    For Each el In els
        Debug.Print el.href '<< pass this to Workbook.Open() then you can save the
                            '    workbook where you need
    Next


End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...