balta2ar / brotab

Control your browser's tabs from the command line
MIT License
389 stars 27 forks source link

Cannot access specific tab text/html contents #72

Open philipsd6 opened 2 years ago

philipsd6 commented 2 years ago

I'd like to be able to retrieve the HTML/text from a specific tab, however, it seems it's only possible to call get_html() to get the HTML for all the /active/ tabs. I would like to be able to loop through tabs of interest and activate them unfocused so they load the HTML, and then be able to retrieve just that HTML. I have > 600 tabs open, so it's unreasonable to try to activate all of them so I can get all the HTML and then get the ones I want.

Conceptually what I want to do is this:

tabs = client.list_tabs()
my_tabs = [Tab(tab) for tab in tabs if "such and such" in tab]
for tab in my_tabs:
    client.activate_tab(tab.id, focused=False)  # ensure the tab has HTML loaded
    contents = client.get_html(tab.id)
    do_something(tab, contents)
    client.close_tab(tab.id)  # or unload -- I wish we could! I'll make a feature request!

All I can do now though is process the current results of get_html() and then close those tabs, refresh and start over.