I'm trying to scrape data from a webpage. In this process, I need to change one of the dropdown of that web page. I was able to do that. But when I manually change the dropdown, webpage changes it's content like images and some other text. But when I do that using VBA it doesn't do that. I tested my code several times. So if I run the program 10 times it will change the content 1 or 2 times. So I'm confused about what happening
This is the HTML of that dropdown area.
<tbody>
<tr>
<td class="label"><label for="pa_product">Product</label></td>
<td class="value"><select id="pa_product" name="attribute_pa_product" data-attribute_name="attribute_pa_product">
<option value="">Choose an option…</option>
<option value="air-xs-2-octo-16-inch" class="attached enabled">AIR XS 2 Octo 16 Inch</option>
<option value="air-xs-2-octo-18-inch" class="attached enabled">AIR XS 2 Octo 18 Inch</option>
<option value="air-xs-2-octo-20-inch" class="attached enabled">AIR XS 2 Octo 20 Inch</option>
</select> <a class="reset_variations" href="#reset">Clear selection</a></td>
</tr>
</tbody>
And this is the code I have developed. I think onchange and onclick work rarely.
Do
DoEvents
Loop Until objIE.readystate = 4
'Body(HTML)
'MsgBox objIE.document.getElementById("tab-description").outerHTML, , "OHTML"
'MsgBox objIE.document.getElementById("tab-description").innerHTML, , "IHTML"
'MsgBox objIE.document.getElementById("tab-description").innerText, , "ITex"
WS.Range("D" & i).Value = objIE.document.getElementById("tab-description").outerHTML
'Option 1 value
'MsgBox objIE.document.getElementById("pa_product").outerHTML
'MsgBox objIE.document.getElementById("pa_product").innerHTML
'MsgBox objIE.document.getElementById("pa_product").innerText
objIE.document.getElementById("pa_product").selectedindex = 1
Application.Wait (Now + TimeValue("0:00:01"))
'modify the web page for that selected item
'For x = 1 To 5
'objIE.document.getElementById("pa_product").selectedindex = 1
Application.Wait (Now + TimeValue("0:00:03"))
objIE.document.getElementById("pa_product").FireEvent ("onchange")
objIE.document.getElementById("pa_product").FireEvent ("Onclick")
objIE.document.getElementById("pa_product").FireEvent ("onmousedown")
'Next x
Application.Wait (Now + TimeValue("0:00:03"))
WS.Range("J" & i).Value = objIE.document.getElementById("pa_product").Item(1).innerText
Thank you very much.
Aucun commentaire:
Enregistrer un commentaire