scrapy 如何在混战中刮收视率?

yc0p9oo0  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(200)

我正在用scrapy刮这个网站。我似乎不能刮的评级。下面是代码
进口废钢

class nykacr(scrapy.Spider):
    name = 'nykaa'
    start_urls = ['https://www.nykaa.com/nykaa-so-creme-creamy-matte-lipstick/reviews/683166?skuId=683163&ptype=reviews']

    def parse(self,response):
        review = response.css('.description::text').getall()
        username = response.css('.user-name::text').getall()
        shade = response.css('.shade::attr(alt)').getall()
        print(review)
        print(username)
        print(shade)
mo49yndu

mo49yndu1#

添加此行以获取评级

rating = response.css('.rating::text').getall()

如果你添加yield而不是print,也可以保存json文件。

def parse(self,response):
        review = response.css('.description::text').getall()
        username = response.css('.user-name::text').getall()
        shade = response.css('.shade::attr(alt)').getall()
        rating = response.css('.rating::text').getall()
        yield{
            'review':review,
            'username':username,
            'shade':shade,
            'rating':rating,
        }

便奔本荐去了。

scrapy crawl nykaa -o test.json

您可以获取此test.json文件。

[
    {
        "review": [
            "Beautiful color , lovely soft texture , nice packaging.\r\nGo for it !",
            "Love love love!! Pretty shade. Yes it is a cream lipstick and it is not transfer proof which is completely fine by me. I love this nude brown shade and is a perfect cream lipstick for this cold weather as it doesn't dry out my lips. Cannot explain how delighted i am to receive this.",
            "I am not into nude shades. I didn't liked them unless I tried this one. I just loved it, the creamy texture, smell, and it's very light weight. I have pink and blakish lips but it still suits me. Thanks Nykaa \ud83d\ude01",
            "My first purchase from nykaa . really gud color bt it's too creamy.i always use Maybelline newyork bt it compete that.",
            "What an amazing shade this is. Loblve it love it.. really try this shade so amazing formula and so comfortable on wearing. Nice product. Love it\r\n",
            "Nice one, Game on is the shade ... Best shade I ever use... Love it so much.. ",
            "Yes \ud83d\udc95 it's so creamy and perfect nude pink for summer I just this \ud83d\udc4d lipstick\ud83d\udc84 \r\n\r\n",
            "It's trending and I bought it, very fast delivery by naayka",
            "It's a nude brown shade...muted colour for a mature look..packaging was bad no box no cover it just comes freely with nothing and also in a nutshell the product is good for the price ?",
            "This lipshade is super super creamy . Specially i love the shade of this lipstick ( ON FIRE ) this shade is really good , and brighten in sunshine. This lipstick is not completely Matte It just give creamy texture to the lips nd it is super creamy . Let me make it clear the shade of this lipstick , it is little pinkish red in shade . M fully satisfied with this product \r\nIn reality This lipshade Will put your looks on fire ",
            "So so so pretty shade \u2026. I love this shade too much \ud83e\udd70\ud83d\ude18 So nice texture \u2764\ufe0f .. so creamy \ud83d\ude0d\ud83d\udc4c ",
            "Perfectttt shade  ",
            "It's a kind of tangy red with the slightest hit of orange beautiful colour though can suit every Indian skin tone  happy with the purchase \u2764\ufe0f",
            "I have many shades of the range but this stile my heart",
            "This line of lipsticks from Nykaa has become my personal favourite.! This one is a daily wear shade and suits my medium skin tone beautifully! If you're eyeing this particular shade then Go For It ! You won't regret it!",
            "Absolute love! Another beautiful shade from this line. My recent fav. lipstick. Completely in love.  This one is a peachy nude with pink undertone. Lovely lipstick, very creamy and glides smoothly over the lips. Love it! Cannot wait to try other varients. Just love this.\r\nWait did i mention I LOVE IT!!??",
            "I loved It..Best Shade...It suits all skin color..Nice one",
            "It's awesome",
            "I purchased NYKAA pep talk shade \r\nIt has  creamy texture but not Matt texture \r\nIt stays on lips only if not eaten nothing \r\nIt is beautiful pink color \r\nSuitable with Indian bridal attire and Indian makeup \r\nVery suitable for fair girls complexion ",
            "Light maroon colour"
        ],
        "username": [
            "Tavleen Kaur",
            "Nikki Roberts",
            "Shilpa Sharma",
            "Priyanka Bhardwaj",
            "Dia Sharma",
            "Yukta Sharma",
            "Rishleen Nargass",
            "Shraddha Parmar",
            "Preethi Runali",
            "swati 2402",
            "Bhumi patel",
            "Komal Honmane",
            "Honey Makwana",
            "harvi akbari",
            "Nikki Roberts",
            "Nikki Roberts",
            "Maya Nikhil",
            "Rai Ghosh",
            "komal gp",
            "Namita Soy"
        ],
        "shade": [
            "Wakeup Makeup",
            "You're Latte",
            "You're Latte",
            "Gossip Dose",
            "Break a Leg",
            "Game On",
            "Traffic Jammin'",
            "Game On",
            "Deja Nude",
            "On Fire",
            "Break a Leg",
            "Wakeup Makeup",
            "Bon Appetit Baby",
            "Deja Nude",
            "Wakeup Makeup",
            "Break a Leg",
            "Let it Snooze",
            "Gossip Dose",
            "Pep Talk",
            "Break a Leg"
        ],
        "rating": [
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5",
            "5"
        ]
    }
]

相关问题