Closed AbhimanyuAryan closed 2 years ago
ok so I managed to call
sync_playwright.sync_playwright()
PyObject <playwright.sync_api._context_manager.PlaywrightContextManager object at 0x7fa2950dde20>
but now I want to run
sync_playwright.sync_playwright().chromium.launch()
which says
sync_playwright.sync_playwright().chromium.launch()
ERROR: KeyError: key :chromium not found
Stacktrace:
[1] __getproperty(o::PyObject, s::Symbol)
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/PyCall.jl:307
[2] getproperty(o::PyObject, s::Symbol)
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/PyCall.jl:312
[3] top-level scope
@ REPL[14]:1
do I need to read python code and manually call each and every method/object/module while wrapping it with PyCall.jl?
sync_playwright = pyimport("playwright.sync_api")
This imports the sync_api
module, not the function, which is why it gives a module object. It's equivalent to import playwright.sync_api as sync_playwright
, which is not what you want. You want
sync_playwright = pyimport("playwright.sync_api").sync_playwright
I guess.
The analogue of the Python with
construct is @pywith
. Have you tried:
@pywith sync_playwright() as p begin
browser = p.chromium.launch()
page = browser.new_page()
page.goto("http://playwright.dev")
println(page.title())
browser.close()
end
?
If you are still getting an issue with p.chromium
, maybe you have some missing component in your Python installation.
@stevengj so basically. playwright
after conda installation asks you to install chromium
firefox
components which you do by calling
playwright install
from terminal (in conda_jl environment). It worked downloaded chromium
, firefox
etc. Works in Python version. But this doesn't work in PyCall
. I didn't call playwright install
from conda.jl
or pycall.jl
I was not sure how. Instead called it from python's virtual env conda_jl
which is configured with conda.jl
and python.jl
Was I suppose to call playwright install
via conda.jl
or pycall.jl
I installed playwright
with Conda.pip("install", "playwright")
ok it worked 2nd time. Thanks a ton @stevengj
julia> @pywith sync_playwright() as p begin
browser = p.chromium.launch()
page = browser.new_page()
page.goto("http://playwright.dev")
println(page.title())
browser.close()
end
Fast and reliable end-to-end testing for modern web apps | Playwright
First time it gave me error:
julia> @pywith sync_playwright() as p begin
browser = p.chromium.launch()
page = browser.new_page()
page.goto("http://playwright.dev")
println(page.title())
browser.close()
end
ERROR: PyError ($(Expr(:escape, :(ccall(#= /Users/arstar/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'playwright._impl._api_types.Error'>
Error('net::ERR_NAME_NOT_RESOLVED at http://playwright.dev/\n=========================== logs ===========================\nnavigating to "http://playwright.dev/", waiting until "load"\n============================================================')
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/sync_api/_generated.py", line 7278, in goto
self._sync(
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_sync_base.py", line 111, in _sync
return task.result()
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_page.py", line 466, in goto
return await self._main_frame.goto(**locals_to_params(locals()))
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_frame.py", line 119, in goto
await self._channel.send("goto", locals_to_params(locals()))
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 39, in send
return await self.inner_send(method, params, False)
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 63, in inner_send
result = next(iter(done)).result()
Stacktrace:
[1] top-level scope
@ ~/.julia/packages/PyCall/L0fLP/src/PyCall.jl:656
caused by: PyError ($(Expr(:escape, :(ccall(#= /Users/arstar/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'playwright._impl._api_types.Error'>
Error('net::ERR_NAME_NOT_RESOLVED at http://playwright.dev/\n=========================== logs ===========================\nnavigating to "http://playwright.dev/", waiting until "load"\n============================================================')
Loop <_UnixSelectorEventLoop running=False closed=True debug=False> that handles pid 51837 is closed
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/sync_api/_generated.py", line 7278, in goto
self._sync(
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_sync_base.py", line 111, in _sync
return task.result()
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_page.py", line 466, in goto
return await self._main_frame.goto(**locals_to_params(locals()))
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_frame.py", line 119, in goto
await self._channel.send("goto", locals_to_params(locals()))
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 39, in send
return await self.inner_send(method, params, False)
File "/Users/arstar/miniconda3/envs/conda_jl/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 63, in inner_send
result = next(iter(done)).result()
Stacktrace:
[1] pyerr_check
@ ~/.julia/packages/PyCall/L0fLP/src/exception.jl:62 [inlined]
[2] pyerr_check
@ ~/.julia/packages/PyCall/L0fLP/src/exception.jl:66 [inlined]
[3] _handle_error(msg::String)
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/exception.jl:83
[4] macro expansion
@ ~/.julia/packages/PyCall/L0fLP/src/exception.jl:97 [inlined]
[5] #107
@ ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:43 [inlined]
[6] disable_sigint
@ ./c.jl:458 [inlined]
[7] __pycall!
@ ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:42 [inlined]
[8] _pycall!(ret::PyObject, o::PyObject, args::Tuple{String}, nargs::Int64, kw::Ptr{Nothing})
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:29
[9] _pycall!
@ ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:11 [inlined]
[10] #_#114
@ ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:86 [inlined]
[11] (::PyObject)(args::String)
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:86
[12] macro expansion
@ REPL[25]:4 [inlined]
[13] top-level scope
@ ~/.julia/packages/PyCall/L0fLP/src/PyCall.jl:652
looks like network error: net::ERR_NAME_NOT_RESOLVED
I am new to PyCall. I'm trying to use
playwright python API
with PyCallso I basically tried
Now I want to achieve this:
but I get this error: