Python 使用xpath从单个DIV类中获取多个选择性值
我正在使用Xpath和Python创建一个网站,希望在一个文件中返回多个元素Python 使用xpath从单个DIV类中获取多个选择性值,python,xml,xpath,screen-scraping,Python,Xml,Xpath,Screen Scraping,我正在使用Xpath和Python创建一个网站,希望在一个文件中返回多个元素 div class 我已经用计算机缩小了讨论中的信息范围 //*[@class='category-product js-productitem'] 此选项位于Pastebin上: 我希望能够从这个选择中提取多个信息位。例如,“数据产品ID”、“数据价格”、“数据特殊价格”等 我想了解如何将Xpath等效于SQL SELECT data-productid, data-price, data-specialpri
div class
我已经用计算机缩小了讨论中的信息范围
//*[@class='category-product js-productitem']
此选项位于Pastebin上:
我希望能够从这个选择中提取多个信息位。例如,“数据产品ID”、“数据价格”、“数据特殊价格”等
我想了解如何将Xpath等效于SQL
SELECT data-productid, data-price, data-specialprice FROM category-product js-productitem
在学习Xpath时,绝对/相对路径让我有些困惑。我假设,如果我以这种方式引用标签/名称的唯一组合(而不是相对路径),我可以确保只获得我期望的信息,通过Google Chromes的“检查”功能进行检查。使用“根路径”和@attribute符号来获取(get())您需要的信息。带刮壳:
response.xpath('//*[@class='category-product js-productitem']/@data-productid').get()
response.xpath('//*[@class='category-product js-productitem']/@data-price').get()
response.xpath('//*[@class='category-product js-productitem']/@data-specialprice').get()