2017-08-01 17 views
1

私はこのサイトから曲の名前を取得しようとしていますhttps://pagalworld.me/category/11598/Latest%20Bollywood%20Hindi%20Mp3%20Songs%20-%202017.htmlリンク抽出機能を使用していますが、結果は繰り返しています。治療の結果が繰り返されます

import scrapy 
from scrapy import Request 
from scrapy.linkextractors import LinkExtractor 
from scrapy.spiders import CrawlSpider, Rule 
class RedditSpider(CrawlSpider): 
    name='pagalworld' 
    allowed_domains = ["pagalworld.me"] 
    start_urls=['https://pagalworld.me/category/11598/Latest%20Bollywood%20Hindi%20Mp3%20Songs%20-%202017.html'] 
    rules = ( 
     Rule(
     LinkExtractor(restrict_xpaths='//div/ul'), 
     follow=True, 
     callback='parse_start_url'), 
    ) 
    def parse_start_url(self, response): 
     songName= response.xpath('//li/b/a/text()').extract() 

     for item in songName: 

      yield {"songName":item, 
     "URL":resposne} 

Output

+0

出力と、完全なコード(異議の具体例も含む)を投稿してください。 – TrakJohnson

答えて

1

すべてはあなたのクモで正しいと思われます。

$ scrapy shell "https://pagalworld.me/files/12450/Babumoshai%20Bandookbaaz%20(2017)%20Movie%20Mp3%20Songs.html" 
>[1]: response.xpath('//li/b/a/text()').extract() 
<[1]: 
['03 Aye Saiyan - Babumoshai Bandookbaaz 190Kbps.mp3', 
'03 Aye Saiyan - Babumoshai Bandookbaaz 320Kbps.mp3', 
'01 Barfani - Male (Armaan Malik) 190Kbps.mp3', 
'01 Barfani - Male (Armaan Malik) 320Kbps.mp3', 
'02 Barfani - Female (Orunima Bhattacharya) 190Kbps.mp3', 
'02 Barfani - Female (Orunima Bhattacharya) 320Kbps.mp3'] 

つのバージョンが低い190kbpsの品質であり、他方はより高320kbpsの品質です:あなたは歌のページを見ればしかし、それは各曲の2つのバージョンを提供しています。

>[2]: response.xpath('//li/b/a/text()[contains(.,"320Kb")]').extract() 
<[2]: 
['03 Aye Saiyan - Babumoshai Bandookbaaz 320Kbps.mp3', 
'01 Barfani - Male (Armaan Malik) 320Kbps.mp3', 
'02 Barfani - Female (Orunima Bhattacharya) 320Kbps.mp3'] 

編集:あなたはおそらくちょうどそれらの1を維持したい。この中
重複の問題もあるよう は思えます。この場合は追いかけたくないので、リンク抽出プログラムでfollow=Trueを無効にしてみてください。

+0

followの目的は何ですか?私はここでhttps://docs.scrapy.org/en/latest/topics/link-extractors.htmlを見ていましたが、何も見つかりませんでした。 – emon

+0

@emonはそれ自身が見つけたページにLinkExtractorルールを適用し続けます。だからこの場合、それはあらかじめ見つけた曲のページで曲のURLを探します。 – Granitosaurus

+0

デフォルト値はFalseですか? – emon