@Raz, I found this old project of mine that is intended to help in scraping.
You define a handler for urls like this:
class DemoScraper(WebScraper):
def __init__(self, webview):
super().__init__(webview)
self.url_map = {
self.login_page: 'https://some.url',
}
self.handler = self.login_page
Hit the first page with something like this:
wv = ui.WebView()
ds = DemoScraper(wv)
wv.load_html('https://some.url')
wv.present('fullscreen')
Then in the handler functions you can access and manipulate js with these chainable helpers:
def login_page(self):
assert self.by_id('test').to_string() == '[object HTMLDivElement]'
assert self.xpath('head/title').to_string() == '[object HTMLTitleElement]'
assert self.xpath('head/title').value() == 'Test document'
assert self.value('head/title') == 'Test document'
assert self.xpath('*[@class="test_class"]').to_string() == '[object HTMLDivElement]'
test_div = self.by_id('test')
assert test_div.style('top') == 100.0
assert test_div.style('backgroundColor') == 'inherit'
assert test_div.abs_style('backgroundColor') == 'rgb(0, 0, 255)'
test_div.set_style('left', 5)
assert test_div.abs_style('left') == 5.0
cell_values = self.for_each('table//tr').map(
key='td[1]',
some_value='td[3]'
)
assert cell_values == {'A1': {'some_value': 'A3'}, 'B1': {'some_value': 'B3'}}
names = self.list_each('input/@name')
assert names == [ 'username', 'passwd' ]
self.set_field('username', 'your username')
self.set_field('passwd', 'your password')
# Explicitly set the handler for the
# next page
self.handler = self.other_page
self.by_name('form1').submit()