|
以下を示すために使用しますunion
。
xpath3 = "//span[@class='productSpecialPrice']//text()|//div[@class='proDetPrice']//text()"
これはまさにあなたが求めたものではありませんが、実行可能なソリューションに組み込むことができると思います.
XPath (バージョン 1.0) 仕様から:
| | 演算子は、そのオペランドの和集合を計算します。これは、ノード セットでなければなりません。
例えば、
import lxml.html as LH
urls = [
'http://jujumarts.com/mobiles-accessories-smartphones-wildfire-sdarkgrey-p-551.html',
'http://jujumarts.com/computers-accessories-transcend-500gb-portable-storejet-25d2-p-2616.html'
]
xpaths = [
"//span[@class='productSpecialPrice']//text()",
"//div[@class='proDetPrice']//text()",
"//span[@class='productSpecialPrice']//text()|//div[@class='proDetPrice']//text()"
]
for url in urls:
doc = LH.parse(url)
for xpath in xpaths:
print(doc.xpath(xpath))
print
収量
['Rs.11,800.00']
['Rs.13,299.00', 'Rs.11,800.00']
['Rs.13,299.00', 'Rs.11,800.00']
[]
['Rs.7,000.00']
['Rs.7,000.00']
必要な情報を得るもう 1 つの方法は、
"//*[@class='productSpecialPrice' or @class='proDetPrice']//text()"