如何在HttWebRequest中读取某个字符串

时间:2017-02-19 01:41:45

标签: html vb.net http bots

我正在尝试使用HTTPWebRequest从多个网站获取价值

这是一个更难的LINK我试图从组合框中获取价格

这是一个更简单的(我认为),LINK

如何解析pricetag?

1 个答案:

答案 0 :(得分:0)

这是VBA的答案,很容易移植到.Net。

Sub test()
    'Add a reference to MSXML 6.0
    Dim getreq      As New MSXML2.ServerXMLHTTP60
    Dim html        As Object: Set html = CreateObject("htmlfile")
    Dim elements    As Object
    Dim element     As Object

    'Get the HTML from the server
    With getreq
        .Open "GET", "http://us.bape.com/collections/men/products/1d30-141-006"
        .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
        .send
        .waitForResponse 5

        'Create an in memory HTML document with the page's HTML
        html.body.innerhtml = .responseText
    End With

    'Print out the InnerText, use getelementbyid to find the element
    Debug.Print html.getelementbyid("product-select").innertext

    'If there are multiple options, find the element, then iterate the options
    'Set elements = html.getelementbyid("product-select").getElementsByTagName("option")

    'iterate the options
    'For Each element In elements
    '    Debug.Print element.innertext
    'Next
End Sub