用循环更改链接

时间:2018-03-15 12:14:32

标签: excel vba excel-vba loops

For x = 1 To 40

    objIE.navigate "http://example.com/market/search?appid=578080#pX_name_asc" '---> here is pX_name_asc
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
    MsgBox "Check Point 1"

    y = 1
    For Each itemEle In objIE.document.getElementsByClassName("market_listing_row_link")
        Prc1 = itemEle.getElementsByClassName("market_listing_item_name_block")(0).getElementsByTagName("span")(0).textContent
        Sheets("Sheet1").Range("E" & y).Value = Prc1
        y = y + 1
    Next

Next x

我只需更改objIE.navigate "http://example.com/market/search?appid=578080#pX_name_asc"p1_name_ascp2_name_asc,...,p40_name_asc

我尝试使用For … Next循环(如您所见)来更改链接,但我认为它不适用于更改链接:)

1 个答案:

答案 0 :(得分:1)

使用基本字符串连接将 x 拼接到url字符串中。

objIE.navigate "http://steamcommunity.com/market/search?appid=578080#p" & x & "_name_asc"