3

Basically I have installed an auto page refresher on safari. And I have 5 Safari windows auto refreshing every 30 sec. My goal is to use python to get a list of all the open web pages. I am using this to do it:

import appscript
urls = appscript.app('Safari').windows.tabs.URL()
urls

This returns a list of open tabs with the urls. Next thing is to fetch the source code of all these open tabs and save it to txt or html and then finally use python to match a string on the webpage to get to the data I want.

How do I get the page source of the already open webpages and save them to txt or html? Can this be done using appscript or some other module?

Naresh
  • 2,761
  • 10
  • 45
  • 78
achillez16
  • 31
  • 3
  • you have the urls, so now you just need to ''scrape'' the web page. i recommend looking at beautifulsoup and working through some of their examples. . – benten Sep 25 '16 at 02:55
  • 1
    Forgot to mention the website has a login so can't use scrapping. I wanted to avoid all the loging in to the website and just use the source code that has already been downloaded by the browser. – achillez16 Sep 25 '16 at 02:57

1 Answers1

0

this works for me :)

import appscript
print (appscript.app("Safari").windows.first.current_tab.source.get())
vimuth
  • 5,064
  • 33
  • 79
  • 116
Jan Devera
  • 11
  • 1