-2
我想用一些庫將css選擇器轉換爲xpath。誰能給我解釋一下什麼是返回值的意思,我怎麼能覆蓋到的XPath像//div//*[[email protected]""]
如何使用cssselector將css轉換爲xpath
from cssselect import GenericTranslator
try
sel = CSSSelector('div.w3-container.top')
except SelectorError:
print('Invalid selector.')
print(sel)
sel:
'descendant-or-self::div[@class and contains(concat(\\' \\', normalize-space(@class), \\' \\'), \\' w3-container \\') and (@class and contains(concat(\\' \\', normalize-space(@class), \\' \\'), \\' top \\'))]'
這是xapth,不需要轉換。由於它以'descendant-or-self'開始,因此它希望您在要作爲搜索根目錄的節點上啓動查詢。你可以用'//'來獲得root權限。 – tdelaney
發佈的代碼不起作用(CSSSelector未定義)。你可以更新一些對其他人有用的事情嗎? – tdelaney