A
A
arsenaljek2022-03-15 10:29:03
Google Sheets
arsenaljek, 2022-03-15 10:29:03

IMPORTXML skips lines when parsing. How to decide?

I'm trying to display all the articles, but it only outputs through the line

=IMPORTXML("https://www.triatron.ru/catalog/index.php?rodgr=27576&gr=9832,214848&filter%5B0%5D%5B%5D=TITAN&sort=0&dir=0&p=1&all=1";"//div[@class=('t-row-div')]//div[1][@class='t-cell-div']")

because the second div is called t-row-div odd_row.
How to write a condition in xpath so that he understands that you need to look at div and t-row-divandt-row-div odd_row

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2022-03-15
@arsenaljek

Example in Spreadsheet https://docs.google.com/spreadsheets/d/1gpb-ZRLUW5...
Specify not the exact match of the class, but its content in the attribute
div[contains (@class, 't-row-div')]

=IMPORTXML(
  "https://www.triatron.ru/catalog/index.php?rodgr=27576&gr=9832,214848&filter%5B0%5D%5B%5D=TITAN&sort=0&dir=0&p=1&all=1";
  "//div[contains (@class, 't-row-div')]//div[1][@class='t-cell-div']"
)

Perhaps your sample is unexpected, because there are spaces between cells. This is because you are selecting an array and not a branch in a tree. Compare the second //divand /div:
"//div[contains (@class, 't-row-div')]//div[1][@class='t-cell-div']"

and
"//div[contains(@class, 't-row-div')]/div[1][@class='t-cell-div']"

  • //- select all sets down the tree
  • /- select next branch

62307381dfa08035413307.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question