网址= https://www.ebay.in/sch/Watches-/14324/i.html
我想从这个URL
地址中提取价格,请在XPath
帮助我。另外,在查看价格时,解释一下这个== $ 0在Google Chrome开发者工具中意味着什么?
应用xpath
来获取价格的元素是:
<li class="lvprice prc">
<span class="bold">
<b>Rs.</b> 2,190.00</span>
</li>
答案 0 :(得分:0)
尝试以下方式获取名称和价格:
import requests
from scrapy import Selector
res = requests.get("https://www.ebay.in/sch/Watches-/14324/i.html")
sel = Selector(res)
for items in sel.xpath("//*[contains(@id,'item')]"):
name = items.xpath(".//*[@class='vip']/text()").extract_first()
price = items.xpath(".//*[@class='bold']/b[.='Rs.']/following::text()").extract_first()
print(name,price)
部分输出:
Imported Emporio Armani Chronograph AR2448 Classic Blue Dial Men's Watch Gift 2,190.00
Daniel Wellington Couple Watch 749.00
IMPORTED EMPORIO ARMANI AR5889 BLACK SILICONE MENS CHRONOGRAPH WATCH DATE GIFT 2,691.00
Luxury Mens Black Dial Gold Stainless Steel Date Quartz Analog Sport Wrist Watch 499.00
Import Emporio Armani AR2448 Classic Blue Dial Men's Watch 2,295.00