Loop web scraping

Hi
I just need a push in the right direction to get going…
I was testing web scraping. If I loop 4 times I only get the first element (link text) on the page 4 time instead of the next elements.
I have tried different ways to write the xpath with no luck.

As I see it the loop open the webpage 4 times and grab the first element instead of actually looping through the elements. Can any one help?

You must create a loop to increment the values to scrape

Here macro code and image, add only csvsave part, I scraped and saved in var and notify the result, you must add csvsave only.

I added 5 times loop but you can edit this value to prefered loop number.

{
  "Name": "Scrapes",
  "CreationDate": "2019-12-30",
  "Commands": [
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "bringBrowserToForeground",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://en.wikipedia.org/wiki/List_of_dinosaur_genera",
      "Value": ""
    },
    {
      "Command": "waitForPageToLoad",
      "Target": "10000",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "0",
      "Value": "Loop_Counter"
    },
    {
      "Command": "label",
      "Target": "Macro_Code",
      "Value": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${Loop_Counter}) + 1",
      "Value": "Loop_Counter"
    },
    {
      "Command": "storeText",
      "Target": "xpath=//*[@id=\"mw-content-text\"]/div/ul[2]/li[${Loop_Counter}]/i/a",
      "Value": "Dinosaur"
    },
    {
      "Command": "echo",
      "Target": "Scraping Element Number ${Loop_Counter} Is: ${Dinosaur}",
      "Value": "#shownotification"
    },
    {
      "Command": "gotoIf_v2",
      "Target": "${Loop_Counter} < 5",
      "Value": "Macro_Code"
    }
  ]
}

1 Like