Skip to content

Suggestion for Scraping Steam Project #33

Open

Description

@graciedevine
  • Book order number: 10379
  • Book build date: 2020-09-23-alpha
  • Book format (PDF, Epub or Mobi): PDF
  • Chapter: 2
  • Section: 2.7

Description

Hello! I was doing the web scraping project in PyCharm and it suggested using a dictionary literal for Lines 27-33. So, instead of:

	resp = {}
	resp['title'] = info[0]
	resp['price'] = info[1]
	resp['tags'] = info[2]
	resp['platforms'] = info[3]
	output.append(resp)

Possible Solutions

PyCharm suggested writing it as:

    resp = {'title': info[0], 'price': info[1], 'tags': info[2], 'platforms': info[3]}
    output.append(resp)

I think this would be good to include since list comprehensions are presented in this chapter too.

Your full name so I can provide accurate credit within the book

Gracie Devine

Activity

  1. ivangeorgiev commented on Dec 29, 2021

    @ivangeorgiev

    I have a bit different suggestion about this:

    from collections import namedtuple
    
    Game = namedtuple("Game", "title,price,tags,platforms")
    
    output = [Game(*info)._asdict() for info in zip(titles, prices, tags, platforms)]

    Another approach would be to use custom JSON serializer. Illustrated on dataclass instead of namedtuple:

    import json
    from dataclasses import dataclass
    
    @dataclass(frozen=True)
    class Game:
        title:str
        price:str
        tags:list
        platforms:list
    
    class EnhancedJSONEncoder(json.JSONEncoder):
            def default(self, o):
                if dataclasses.is_dataclass(o):
                    return dataclasses.asdict(o)
                return super().default(o)
    
    output = [Game(*info) for info in zip(titles, prices, tags, platforms)]
    json.dumps(output, cls=EnhancedJSONEncoder)
  2. feexie commented on Dec 4, 2023

    @feexie

    cant understand the div class; i try to find the popular release but i couldn't find it! any help or suggestion please?

  3. feexie commented on Feb 28, 2024

    @feexie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions