Home > other >  Web Scraping Google-Sheets ImportXML - xpath - specific Number in URL
Web Scraping Google-Sheets ImportXML - xpath - specific Number in URL

Time:11-24

I am trying to get a specific Number from an URL, which is hyperlinked on the website.

Please see here a copy of my spreadsheet.

In Row "I" - i did a code, so it will directly go the the search of the eBay website, and combines the EAN number ="https://www.ebay.de/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw="&""&D2

this is the outcome: https://www.ebay.de/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw=8713439712292

Till here it works.

On the page, i want the ebay Kategorie ID for that articel, which can be found as a Hyperlink on the Categories [See Image of eBay Categorie here] Navigation on the left. In the URl it is always the first Number, eg. https://www.ebay.de/sch/**158817**/i.html?_from=R40&_nkw=650135421227 InspectCode URL I need

All I want know, is to put the Number 158817 in my google spreadsheet.

With this code

=IMPORTXML(I2;"//*[@id='x-refine__group__0']/ul/li/ul/li/ul")

I only get the categorie name, but I need the number to make my CSV upload work.

What code do I need? Can Someone please guide me? thank you Lisa

CodePudding user response:

With A1 = https://www.ebay.de/sch/**158817**/i.html?_from=R40&_nkw=650135421227, try this

=regexextract(IMPORTXML(A1;"//*[@id='x-refine__group__0']/ul/li/ul/li/ul/li/a/@href");"[0-9] ")

assuming that the url is always at the same position in the nomenclature

or, to get all numbers

=arrayformula(regexextract(IMPORTXML(A1;"//*[@id='x-refine__group__0']/ul/li//a/@href");"[0-9] "))
  • Related