我试图从这个页面https://octopart.com/electronic-parts/integrated-circuits-ics获取数据,但是从Specs按钮获取数据。我试着用这个代码来获取产品的名称,但是没有用。你知道吗
class SpecSpider(scrapy.Spider):
name='specName'
start_urls = ['https://octopart.com/electronic-parts/integrated-circuits-ics']
custom_settings = {
'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter',
}
def parse(self,response):
return FormRequest.from_response(response, formxpath="//form[@class='btn-group']", clickdata={"value":"serp-grid"}, callback = self.scrape_pages)
def scrape_pages(self, response):
#open_in_browser(response)
items = SpecItem()
for product in response.xpath("//div[class='inner-body']/div[class='serp-wrap-all']/table[class='table-valign-middle matrix-table']"):
name = product.xpath(".//tr/td[class='matrix-col-part']/a[class='nowrap']/text()").extract()
items['ProductName']=''.join(name).strip()
price = product.xpath("//tr/td['4']/div[class='small']/text()").extract()
items['Price'] = ''.join(price).strip()
yield items
这个xpathresponse.xpath("//div[class='inner-body']/div[class='serp-wrap-all']/table[class='table-valign-middle matrix-table']")
不起作用。你知道吗
有什么建议吗
如果您只需要顶级产品名称,请使用
并提取文本
中间价来自css选择器
您可以使用
.css(selector)
将css与scrapy一起应用您使用了错误的XPATH语法!你知道吗
正确的格式是在“class”前加“@”
在上面的链接中没有“矩阵表”表。你知道吗
尝试使用以下方法:
相关问题 更多 >
编程相关推荐