-1
import scrapy


class WanikaniSpider(scrapy.Spider):
    name = 'japandict'
    allowed_domains = ['www.japandict.com']
    start_urls = ['https://www.japandict.com/lists/jlpt5k']
    
           
    def parse(self, response):
        kanjiler = response.xpath("//div[@class='row']/div/div/div")
        for kanji in kanjiler:
            kanjiicon= kanji.xpath("//div[@class='row']/div/div/div/a/div/span")
            yield{
                'kanjiicon': kanjiicon
            }

I created spider like that. I wanna take kanjiicon as a text. But when I use .get .extract methods its returning empty.
How can I fix that?

2 Answers 2

0

I'm getting output.

CODE:

import scrapy


class WanikaniSpider(scrapy.Spider):
    name = 'japandict'
    allowed_domains = ['www.japandict.com']
    start_urls = ['https://www.japandict.com/lists/jlpt5k']
    
           
    def parse(self, response):
        kanjiler = response.xpath('//*[@class="d-inline-block w-100 text-muted"]')
        for kanji in kanjiler:
            kanjiicon= kanji.xpath('.//*[@class="xlarge text-normal me-4"]/text()').get().replace('\n','').strip()
            
            yield {
                'kanjiicon': kanjiicon
            }

Output:

{'kanjiicon': '右'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '雨'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '円'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '下'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '何'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '火'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '外'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '学'}
2021-08-22 05:58:27 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.japandict.com/lists/jlpt5k>
{'kanjiicon': '間'}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to decode the string to utf-8, ascii doesn't cover Japanese chars.

Try something like:

kanjiicon = kanjiicon.decode('utf-8')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.