HTML scrambling with selenium when options are clicked

I have a script that I use to clear data from websites using selenium.

Sub Body_Building() Dim driver As New WebDriver, post As Object With driver .Start "chrome", "http://www.bodybuildingwarehouse.co.uk" .Get "/optimum-nutrition?limit=all" End With On Error Resume Next For Each post In driver.FindElementsByClass("grid-info") i = i + 1: Cells(i, 1) = post.FindElementByClass("product-name").Text Cells(i, 2) = post.FindElementByXPath(".//span[@class='regular-price']//span[@class='price']|.//p[@class='special-price']//span[@class='price']").Text Next post End Sub 

Is it possible to clear the data from this website using the same or similar methodology so that the result is as shown below in the snapshot

enter image description here

Please see VBA to match the desired result. Thanks SMth80

 Sub optigura_scraper_v2() Dim driver As New ChromeDriver Dim elems As Object, post As Object driver.Get "https://www.optigura.com/uk/product/gold-standard-100-whey/" [A1:D1].Value = [{"Name","Flavor","Size","Price"}] Set elems = driver.FindElementsByXPath("//span[@class='img']/img") i = 2 For n = 1 To elems.Count driver.FindElementsByXPath("//span[@class='img']/img")(n).Click driver.Wait 1000 For Each post In driver.FindElementsByXPath("//div[@class='colright']//ul[@class='opt2']//label") Cells(i, 1) = driver.FindElementByXPath("//h1[@itemprop='name']").Text Cells(i, 2) = post.Text Cells(i, 3) = Split(driver.FindElementByXPath("//li[@class='active']//span[@class='img']/img").Attribute("alt"), "-")(1) Cells(i, 4) = driver.FindElementByXPath("//span[@class='price']").Text i = i + 1 Next post Next n End Sub 
0
source share
1 answer

Check this. This, of course, is not the best technique. However, this will serve your purpose. Btw, the scraper will accurately analyze how the data is displayed on this page.

 Sub optigura_scraper() Dim driver As New ChromeDriver Dim elems As Object, post As Object driver.Get "https://www.optigura.com/uk/product/gold-standard-100-whey/" [A1:D1].Value = [{"Name","Price","Size","Flavor"}] Set elems = driver.FindElementsByXPath("//span[@class='img']/img") i = 2 For N = 1 To elems.Count driver.FindElementsByXPath("//span[@class='img']/img")(N).Click driver.Wait 1000 Cells(i, 1) = driver.FindElementByXPath("//h1[@itemprop='name']").Text Cells(i, 2) = driver.FindElementByXPath("//span[@class='price']").Text Cells(i, 3) = Split(driver.FindElementByXPath("//li[@class='active']//span[@class='img']/img").Attribute("alt"), "-")(1) For Each post In driver.FindElementsByXPath("//div[@class='colright']//ul[@class='opt2']//label") Cells(i, 4) = post.Text i = i + 1 Next post Next N End Sub 
+2
source

Source: https://habr.com/ru/post/1270369/


All Articles