私はscrapyを使用したWebスクレイピングに不慣れです。ウェブサイトをスクレイプしようとしています(コードのURLを参照してください)。ウェブサイトから、「Intimation For%Month %% Year%」テーブルの下にある情報を廃棄し、データをjsonファイルに転送しようとしています。
コマンドの実行中に、「 'NoneType'オブジェクトは反復可能ではありません」というエラーが発生します。
スクレイプクロール引用符-oquotes.json
コード:
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
def start_requests(self):
urls = [
'http://www.narakkalkuries.com/intimation.html#i'
]
def parse(self, response):
for check in response.xpath('//table[@class="MsoTableGrid"]'):
yield{
'data':check.xpath('//table[@class="MsoTableGrid"]/tr/td/p/b//text()').extract_first()
}
問題:Webサイトでは、すべての情報データが同じ名前table @ class = "MsoTableGrid"のテーブルに保存されています。
オプションの私はデータを抽出しようとしました
オプション1
response.xpath('//table[@class="MsoTableGrid"]').extract()
すべてのデータを返す
オプション2
response.xpath('//table[@class="MsoTableGrid"]/tr[i]/td/p/b').extract()
垂直列のいくつかを返します
オプション3
response.xpath('//table[@class="MsoTableGrid"]/tr/td/p/b//text()').extract()[1]
データ全体から最初の要素を返す
質問:
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
def start_requests(self):
urls = [
'http://www.narakkalkuries.com/intimation.html#i'
]
# Here you need to yield the scrapy.Request
for url in urls:
yield scrapy.Request(url)
def parse(self, response):
for check in response.xpath('//table[@class="MsoTableGrid"]'):
yield{
'data':check.xpath('//table[@class="MsoTableGrid"]/tr/td/p/b//text()').extract_first()
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加