Issue
hey i have a list stored in csv (scrapy crawl list)
with sync_playwright() as p:
def handle_response(response): # the endpoint we are insterested in
if ("/search?" in response.url):
items = response.json()["payload"]["results"]
data = ([(item["title"], item["display_price"]) for item in items])
store_data(data)
so the item["display_price"] is a numberic value and its also very small amount = 0.0007 can u help me multiple this number by 1000 times or even do more calcutions on it ? i tried lots of stuff like *1000 but guess my very basic python knowledge is not enough !
Solution
This is just a guess, but it looks like you are dealing with a web based thing, so I suspect that the price is actually still a string. If so, you should be able to do something like this to turn it into a floating point number, then multiply it by 1000.
result = float(item["display_price"]) * 1000
https://docs.python.org/3/library/stdtypes.html describes more about types in Python. If you ever wonder what type a variable is, you can do this:
type(the_variable)
That returns a string describing the type, so you can print it, etc.
Answered By - MattArmstrong
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.