networkdynamics / pytok

A web scraper for TikTok using Playwright
59 stars 6 forks source link

Encountered an error while running the sample code. #1

Closed Hawaii-Yan closed 8 months ago

Hawaii-Yan commented 1 year ago

Thank you for providing the PyTok library.

However,while using the provided sample code, I encountered errors such as: 【TypeError: 'PyTok' object does not support the context manager protocol】; 【NotImplementedError:Output is truncated. View as a [scrollable element]or open in a [text editor]. Adjust cell output [settings]

I have checked my environment and dependencies, but I am still unable to resolve this issue. Is there any additional configuration required, or is the PyTok library currently under maintenance?

Your assistance and guidance would be greatly appreciated.

bendavidsteel commented 1 year ago

The library is for sure in an experimental state, but the code sample from the read me was out of date, so I just updated it. Currently the two example scripts that should be working are the user_example.py and comment_example.py scripts. Together those two scripts allow you to get all the videos from a user's page, and get the comments from those videos.

Hawaii-Yan commented 12 months ago

Sorry, the example you provided is still not working.😭😭😭

bendavidsteel commented 12 months ago

What's the error you're getting?

packocrayons commented 9 months ago

The underlying issue here is that PyTok does not implement a synchronous __enter__, yet the examples do not function within an asynchronous context. I tried calling __aenter__ from a dummy __enter__ but it looks like everything needs to be asynchronous. I'm not good enough at python to know how to purely function in an async environment (can main be asynchronous? I don't think so) but I believe that's the root cause here.

Will do some more reading on asynchronous context managers (I'm trying to use get_videos.py) and hopefully come up with a PR, however for the python expert this is a 5 minute fix.

bendavidsteel commented 8 months ago

See here for running main async!: https://github.com/networkdynamics/pytok/blob/b7bf31f9fb3901e2ff0427de568e4f8c29481a5f/examples/video_example.py#L32