Created
October 25, 2022 06:29
-
-
Save kmike/0a8304a339c2e4edb1d45e70b50a5dbe to your computer and use it in GitHub Desktop.
Using RequestUrl to modify a request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from web_poet import ItemPage, field, RequestUrl, HttpClient, cached_method | |
class MyPage(web_poet.ItemPage): | |
request_url: RequestUrl | |
http: HttpClient | |
@cached_method | |
async def response(self): | |
# create API url from the request url | |
api_url = ... | |
response = await self.http.get(api_url) | |
return response.json() | |
@field | |
async def price(self): | |
resp = await self.response() | |
return resp["data"]["price"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment