0
私はウェブサイト内のリンクからデータを抽出しようとしています。私は、次のよパスは次のとおりです。私は、傷病治療を通じてウェブサイト内のリンクからデータを抽出しようとしており、コードにエラーがあります。
ホームページ抽出する
-links
- データ
-linksは(基本的に、私は有名なのすべてbirth_detailsを抽出しようとしています有名人)
マイscrapyコードは次のとおりです。
import scrapy
class celebritiesItem(scrapy.Item):
Name = scrapy.Field()
Profession = scrapy.Field()
Died_On = scrapy.Field()
Birth_Place = scrapy.Field()
Nationality = scrapy.Field()
Birth_Date = scrapy.Field()
class celebrities(scrapy.Spider):
name = "people"
allowed_domains = ["thefamouspeople.com"]
start_urls = [
"http://www.thefamouspeople.com/famous-people-by-birthday.php"
]
def parse(self, response):
links = response.xpath('//div[@class="pod colorbar
editorial"]//@href').extract()
for link in links:
abs_url = response.xpath('//div[@class="pod colorbar
editorial"]//@href').extract()
yield scrapy.Request(abs_url, callback=self.parse)
#items[]
item = celebritiesItem()
item["Name"] =
response.xpath('//div[@class="section"]//a[2]//text()').extract()
item["Profession"] =
response.xpath('//div[@class="section"]//span//text()').extract()
item["Died_On"] =
response.xpath('//div[@class="section"]//p[1]//text()').extract()
item["Birth_Place"] =
response.xpath('//div[@class="section"]//p[2]//text()').extract()
item["Nationality"] =
response.xpath('//div[@class="section"]//p[3]//text()').extract()
item["Birth_Date"] =
response.xpath('//div[@class="section"]//p[4]//text()').extract()
yield item
と私は次のエラーを取得しています:%タイプ(URL):
昇給の例外TypeErrorは( 'リクエストURLは、STRまたはユニコードでなければなりません、%sになりました'。 名)
適切なURLを作成する必要があります私はextract()の代わりにextract_first()を使用しました。 :) – Priyanka