Lookyloo / PlaywrightCapture

Capture a URL with Playwright
Other
30 stars 3 forks source link

circular import error #92

Closed shivam-Purohit closed 5 months ago

shivam-Purohit commented 5 months ago

When i try to import the Capture. Its throwing circular import. I am using the same code given in the docs for testing

from playwrightcapture import Capture
import asyncio

url = "www.example.com"

async def main():
    async with Capture() as capture:
        await capture.prepare_context()
        entries = await capture.capture_page(url)

asyncio.run(main( ))
Rafiot commented 5 months ago

Woops, you're right, I renamed the method a while ago and forgot to update the readme.

I'm a bit confused by what you mean with throwing circular import because the two problems are:

The readme will be updated in a few min.

shivam-Purohit commented 5 months ago

@Rafiot this is the error i am getting while i run the above code

Traceback (most recent call last):

  File "/home/vboxuser/Desktop/honeynet project/captire/playwright.py", line 1, in <module>

    from playwrightcapture import Capture

  File "/home/vboxuser/.local/lib/python3.10/site-packages/playwrightcapture/__init__.py", line 1, in <module>

    from .capture import Capture  # noqa

  File "/home/vboxuser/.local/lib/python3.10/site-packages/playwrightcapture/capture.py", line 29, in <module>

    from playwright._impl._errors import TargetClosedError

  File "/home/vboxuser/Desktop/honeynet project/captire/playwright.py", line 1, in <module>

    from playwrightcapture import Capture

ImportError: cannot import name 'Capture' from partially initialized module 'playwrightcapture' (most likely due to a circular import) (/home/vboxuser/.local/lib/python3.10/site-packages/playwrightcapture/__init__.py)

Also is there any documentation i refer to, is there other customisation options like setting up a proxy or we just pass the url and get the results?

Rafiot commented 5 months ago

The circular import is due to the name of the file you're using (/home/vboxuser/Desktop/honeynet project/captire/playwright.py). You cannot have a file called playwright.py while the library imports playwright.

The documentation of PlaywrightCapture itself is somewhat lacking, I have to admit. I'll work on that.

In the meantime, the documentation of LacusCore contains most of the settings you can pass to PlaywrightCapture: https://lacuscore.readthedocs.io/en/latest/api_reference.html#id4

And you can look at how it is used in this method: https://github.com/ail-project/LacusCore/blob/main/lacuscore/lacuscore.py#L458

shivam-Purohit commented 5 months ago

oh my bad i didnt knew about that. Also thank you for the resources!

Rafiot commented 5 months ago

Depending on what you want to do, you may find using lookyloo easier. And there is a demo instance: https://lookyloo.circl.lu/

shivam-Purohit commented 5 months ago

Its still under dicussion here