Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to interact | change | modify content inside an ui.webview in pythonista programmatically?
-
Hi pythonista's,
is there a way to interact with content of a website loaded inside an ui.webview e.g. click on a link, push a button and so on and so forth programmatically with python in pythonista?
thanks in advance
-püppi-
-
Requests is probably a better way to download webpages and do HTTP POSTs to simulate interactions (filling in fields, clicking buttons, etc.) with them. However, Requests has a downside in that you do not actually see the web page as you would if you were using ui.WebView.
-
WebView
s also have aneval_js()
method that executes a string of JavaScript code on the current page, that may help if you're working with links/buttons that run JS when pressed. In that case you could simply run the button's JS code usingeval_js()
. -
If doing a lot of 2way comm, requests is easiest to use. You can then display the result in a webview.
For simple stuff, eval_js works well. You can use
eval_js('document.documentElement.innerHTML')
to get current page source. Then you can use bs4 for example to scrape the source.
See http://www.w3schools.com/jsref/met_html_click.asp for an example of directly simulating a mouse click on an element like a button.