xpath在控制台中工作,但在scrapy中不工作

9udxz4iz  于 2023-04-12  发布在  其他
关注(0)|答案(1)|浏览(165)

我正在学习网页抓取,我正在尝试抓取这个网站http://wiki.stat.ucla.edu/socr/index.php/SOCR_Data_MLB_HeightsWeights
所以当我做“scrappy crawl basket”的时候,即使xpath的实验是正确的,结果也是空的。
所以它只给我姓名,团队,位置,身高(英寸),体重(磅),但没有数据
请,如果有答案,请解释这个问题,你是怎么知道的,如果有办法,因为我不想再次失败与同样的问题,谢谢。
我看到了一个类似的问题,有人说那个表不包含我试图删除的body,但还是一样。
它在shell中也不起作用,代码如下:

import scrapy

class BasketSpider(scrapy.Spider):
    name = "basket"
    allowed_domains = ["wiki.stat.ucla.edu"]
     start_urls = ["http://wiki.stat.ucla.edu/socr/index.php/SOCR_Data_MLB_HeightsWeights"]
 
def parse(self, response):
    for row in response.xpath('//table[@class="wikitablet"/body/tr]'):
        yield {
            'name': row.xpath('.//th[1]/text()').get(),
            'team': row.xpath('.//tr/th[2]/text()').get(),
            'position': row.xpath('.//tr/th[3]/text()').get(),
            'height': row.xpath('.//tr/th[4]/text()').get(),
            'weight': row.xpath('.//tr/th[5]/text()').get(),
             }
nr9pn0ug

nr9pn0ug1#

您在XPath中选择了错误的类
它是//table[@class=“wikitable”]
您已使用:[@class=“wikitablet”

相关问题