Debugging with keystroke using async actor?
https://apify.com/templates/python-start
For debugging reasons i would like to output every heading and then waiting for a keystrike using <input("Press")> using the following code code below.
But when i press a key when running the program in the terminal i does not go to the next element.
How can i do this using async so i get every output after a keystroke?
Code:
from future import annotations
from apify import Actor
from bs4 import BeautifulSoup
from httpx import AsyncClient
async def main() -> None:
async with Actor:
actor_input = await Actor.get_input() or {'url': 'https://apify.com/'}
url = actor_input.get('url')
if not url:
raise ValueError('Missing "url" attribute in input!')
async with AsyncClient() as client:
Actor.log.info(f'Sending a request to {url}')
response = await client.get(url, follow_redirects=True)
soup = BeautifulSoup(response.content, 'lxml')
headings = []
for heading in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']):
heading_object = {'level': heading.name, 'text': heading.text}
Actor.log.info(f'Extracted heading: {heading_object}')
input("Press!")
headings.append(heading_object)
await Actor.push_data(headings)
