【发布时间】:2015-10-09 20:33:23
【问题描述】:
我正在尝试使用 python Scraper 获取一些特定网站的一些信息,即一些产品的链接。我正在查看的网站是http://www.ah.nl/producten/verse-kant-en-klaar-maaltijden-salades 我正在寻找的链接如下
如果访问该网站并检查例如元素“Maaltijdsalades”,那么您可以使用 XPath 语法看到链接位于 //ul/li 下。问题是在同一个 HTML 代码中,还有一个地方 //ul/li 用于我不寻找的链接。我使用了下面的蜘蛛,它准确地抓取了我不想要的链接。
我正在使用以下蜘蛛
import scrapy
from ah_links.items import AhLinksItem
class AhSpider(scrapy.Spider):
name = "ah_links"
allowed_domains = ["ah.nl"]
start_urls=['http://www.ah.nl/producten/aardappel-groente-fruit',
]
def parse(self, response):
for sel in response.xpath('//ul/li'):
item = AhLinksItem()
item['title'] = sel.xpath('a/@href').extract()
yield item
我需要帮助来解决这个问题。谢谢。
【问题讨论】:
标签: python html xpath web-scraping scrapy