Crapy错误IndentationError:预期有一个缩进块(Crapy error IndentationError: expected an indented block)

编程入门 行业动态 更新时间:2024-10-25 16:30:18
Crapy错误IndentationError:预期有一个缩进块(Crapy error IndentationError: expected an indented block)

这是我的代码:

from scrapy.spider import Spider from scrapy.selector import Selector from thuctapsinhvietnam.items import ThuctapsinhvietnamItem class ThuctapsinhvietnamSpider(Spider): name = "thuctapsinhvietnam" allowed_domains ["thuctapsinhvietnam.com"] start_urls = [ "http://www.thuctapsinhvietnam.com/thuctap-phuong-vinh-hao-3970.html" ] def parse(self, response): def parse(self, response): cases = Selector(response).xpath('//div[@id="areaThongTinCaNhan"]/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr') for case in cases: item = ThuctapsinhvietnamItem() item['Name'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Phone'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Email'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Dob'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Sex'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['School'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Introduction'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Place'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] yield item

在ubuntu中尝试scrapy时遇到问题,我使用xpath获取数据。 我正在尝试来自这个网站的scrapy信息,但这里有错误:

File "thuctapsinhvietnam_spider.py", line 15 cases = Selector(response).xpath('//div[@id="areaThongTinCaNhan"]/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr') ^ IndentationError: expected an indented block

This is my code:

from scrapy.spider import Spider from scrapy.selector import Selector from thuctapsinhvietnam.items import ThuctapsinhvietnamItem class ThuctapsinhvietnamSpider(Spider): name = "thuctapsinhvietnam" allowed_domains ["thuctapsinhvietnam.com"] start_urls = [ "http://www.thuctapsinhvietnam.com/thuctap-phuong-vinh-hao-3970.html" ] def parse(self, response): def parse(self, response): cases = Selector(response).xpath('//div[@id="areaThongTinCaNhan"]/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr') for case in cases: item = ThuctapsinhvietnamItem() item['Name'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Phone'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Email'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Dob'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Sex'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['School'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Introduction'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] item['Place'] = question.xpath( '//td[3][@class="thongtin"]/text()')extract()[0] yield item

I have problem when try to scrapy in ubuntu, I use xpath to get data. I am trying scrapy information from this website but it has error here:

File "thuctapsinhvietnam_spider.py", line 15 cases = Selector(response).xpath('//div[@id="areaThongTinCaNhan"]/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr') ^ IndentationError: expected an indented block

最满意答案

你有两个这样的:

def parse(self, response): def parse(self, response):

You have two of these:

def parse(self, response): def parse(self, response):

更多推荐

本文发布于:2023-08-03 16:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393617.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有一个   错误   IndentationError   Crapy   block

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!