0
私はウェブサイトを削って、ユーザーの個人的な情報(写真はありません)を非常に大まかに取得しようとしていますが、私が修正した公式文書のチュートリアルスパイダーは同じ出力行を4回繰り返しています行。私のScrapyスパイダーがその複製を複製しているのはなぜですか?
私が使用しているコードのコピーは以下の通りです:
注私は、コードに含まれてきた例のプロファイルは、偽/スパムアカウントであること。すでに削除されている可能性がある場合は、そのURLをサイトの他のURLに置き換えることができます。次のように
import scrapy
class DateSpider(scrapy.Spider):
name = "date"
start_urls = [
'http://www.pof.com/viewprofile.aspx?profile_id=141659067',
]
def parse(self, response):
for container in response.xpath('//div[@class="user-details-wide"]'):
yield {
'Gender': response.xpath("//span[@id='gender']/text()").extract_first(),
'Age': response.xpath("//span[@id='age']/text()").extract_first(),
'State': response.xpath("//span[@id='state_id']/text()").extract_first(),
'Marital status': response.xpath("//span[@id='maritalstatus']/text()").extract_first(),
'Body': response.xpath("//span[@id='body']/text()").extract_first(),
'Height': response.xpath("//span[@id='height']/text()").extract_first(),
'Ethnicity': response.xpath("//span[@id='ethnicity']/text()").extract_first(),
'Does drugs?': response.xpath("//span[@id='drugs']/text()").extract_first(),
'Smokes?': response.xpath("//span[@id='smoke']/text()").extract_first(),
'Drinks?': response.xpath("//span[@id='drink']/text()").extract_first(),
'Has children?': response.xpath("//span[@id='haschildren']/text()").extract_first(),
'Wants children?': response.xpath("//span[@id='wantchildren']/text()").extract_first(),
'Star sign': response.xpath("//span[@id='zodiac']/text()").extract_first(),
'Education': response.xpath("//span[@id='college_id']/text()").extract_first(),
'Personality': response.xpath("//span[@id='fishtype']/text()").extract_first(),
}
ランニング:
scrapy crawl date -o date.scv
Iヘッダーの行がまっすぐ後の結果ではなく、空白や重複Iの行が続いている探していた出力を私は現在、
は、いくつかのファイルを移動し、名前を変更しなければならなかったが、私が動作するようにあなたのコードを得ました。そしてそれはとてもきれいに見えます!あなたの助けをありがとう、私は本当にそれを感謝します。 –
問題ありません。私はあなたを助けることができてうれしいです。 – vold