Forum Archive

How to interact | change | modify content inside an ui.webview in pythonista programmatically?

Pppi

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-

ccc

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.

dgelessus

WebViews also have an eval_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 using eval_js().

JonB

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.