Skip to content

Instantly share code, notes, and snippets.

@kmike
Created October 25, 2022 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmike/0a8304a339c2e4edb1d45e70b50a5dbe to your computer and use it in GitHub Desktop.
Save kmike/0a8304a339c2e4edb1d45e70b50a5dbe to your computer and use it in GitHub Desktop.
Using RequestUrl to modify a request
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