如果没有href,我正在尝试将$_url 设置为“未找到”。
xidel --trace-stack --ignore-namespaces 'https://www.uline.com/Grp_41/Peanuts-and-Dispensers' --user-agent 'Mozilla/5.0 Firefox/94.0.1' \
-f '//(a[@class="cssa"]|a[@class="subgroupName"])/@href' \
--xml --xquery '
let $title := //(h1|div[@class="item-result-desc"]/a)/text()
return <product>
<title>{$title}</title>
<url>{$url}</url>
{
for $model in //(table[@class="subgroupChart"]|table[@class="item-result-price-grid__table"])//tr[position()>2 and not(contains(@class, "subgroupChartHeader"))]
let $link := $model//td[1]//(a|span)
let $name := $link/text()
let $_url := $link/(string(@href), "not-found")
let $price := $model//(td[contains(@class, "PriceCellwebPrice")][1]//attrib|td[contains(@class, "qtyBreaksPriceColumn")][1]//span)/text()
return <model>
{ if ($name) then
<name>{$name}</name>
else()
}
{ if ($price) then
<price>{$price}</price>
else ()
}
{ if ($_url) then
<url>https://uline.com{$_url}</url>
else ()
}
</model>
}
</product>'
有时它是一个链接,有时它是一个跨度。