Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,066
- Office Version
- 2016
- Platform
- Windows
Hi
I am hoping someone can explain why my code is not running when I change it to ebay.co.uk
The code runs in two parts,
1) It opens IE - Ebay
2) It places the products Title, Price and URL in columns A,B,C,
It works fine for .com but not for .co.uk I have checked the classes and they all see to be the same. I have left both link in, .co.uk is in green and as a comment for now, as it only works on 1 url at a time
I am hoping someone can explain why my code is not running when I change it to ebay.co.uk
The code runs in two parts,
1) It opens IE - Ebay
2) It places the products Title, Price and URL in columns A,B,C,
It works fine for .com but not for .co.uk I have checked the classes and they all see to be the same. I have left both link in, .co.uk is in green and as a comment for now, as it only works on 1 url at a time
Code:
Public IE As New SHDocVw.InternetExplorer
Sub GetData()
Dim HTMLdoc As MSHTml.HTMLDocument
Dim othwb As Variant
Dim objShellWindows As New SHDocVw.ShellWindows
Set IE = CreateObject("internetexplorer.application")
With IE
.Visible = True
[COLOR=#008000]'.Navigate "https://www.ebay.co.uk/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw=jackets&_sacat=0"[/COLOR]
.Navigate "https://www.ebay.com/sch/i.html_from=R40&_nkw=ralph+lauren&_sacat=1059&LH_TitleDesc=0&_dmd=1&rt=nc"
While .Busy Or .ReadyState <> 4: DoEvents: Wend
Set HTMLdoc = IE.Document
ProcessHTMLPage HTMLdoc
.Quit
End With
End Sub
[B][COLOR=#ff8c00]THIS is the sub procedure and is in the same module [/COLOR][/B]
Sub ProcessHTMLPage(HTMLPage As MSHTml.HTMLDocument)
Dim HTMLItem As MSHTml.IHTMLElement
Dim HTMLItems As MSHTml.IHTMLElementCollection
Dim HTMLInput As MSHTml.IHTMLElement
Dim rownum As Long
rownum = 1
Set HTMLItems = HTMLPage.getElementsByClassName("s-item__title") [COLOR=#008000]'Gets the TITLE and puts in column A[/COLOR]
For Each HTMLItem In HTMLItems
Cells(rownum, 1).Value = HTMLItem.innerText
rownum = rownum + 1
Next HTMLItem
rownum = 1
Set HTMLItems = HTMLPage.getElementsByClassName("s-item__price") [COLOR=#008000]'Gets the PRICE and puts in column B[/COLOR]
For Each HTMLItem In HTMLItems
Cells(rownum, 2).Value = HTMLItem.innerText
rownum = rownum + 1
Next HTMLItem
rownum = 1
Set HTMLItems = HTMLPage.getElementsByClassName("s-item__link") [COLOR=#008000]'Gets the URL and puts in column C[/COLOR]
For Each HTMLItem In HTMLItems
Cells(rownum, 3).Value = HTMLItem.href
rownum = rownum + 1
Next HTMLItem
[COLOR=#008000]'Converts each text hyperlink selected into a working hyperlink from C1 to 25000 rows[/COLOR]
Range("C1:C25000").Select
For Each xCell In Selection
ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula
Next xCell
Range("C1").Select
End Sub