使用Scrapy和Xpath刮取数据

2024-04-19 18:40:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Scrapy和xpath从一个站点抓取数据,但是遇到了一些问题。这是我的密码:

class MaijiaSpider(scrapy.Spider):
    name = 'maijiaSpider'
    start_urls =["http://www.maijia.com/index.html#/item/list/?keyword=recaro"]

    def parse(self, response):
        articles = response.xpath("//table[@class='ui-table ui-table-striped ui-table-inbox tablefixed']//tr[1]/td[2]/div/div[1]/a/@href")
        for article in articles:
            yield{
                'link': article.xpath('.//td[2]//a/@href').extract_first() 
            }

问题是冠词总是空的,因此它从不进入for循环。我做错什么了?我尝试使用不同的xpath字符串,但似乎没有任何效果。你知道吗


Tags: 数据divui密码for站点responsearticle
1条回答
网友
1楼 · 发布于 2024-04-19 18:40:23

此页面使用JavaScript获取数据,数据的URL为:

http://www.maijia.com/data/item/list?api_name=item_get_list&type=ALL&pageNo=1&pageSize=10&keyword=recaro&sortField=amount30&sortType=desc

你可以在Chrome开发工具中找到这个URL

enter image description here

相关问题 更多 >