OK so have looked at the chrome documentation a little more, and have now got and understand the messaging going between the content, background and popup scripts.
Basically to send a message to content.js, we use chrome.tabs.sendMessage(), and to send a message to the popup or background scripts we us chrome.runtime.sendMessage(), and to listen for a message on popup or background we use chrome.extension.onMessage().
def getText (url):
#get the DOM object from the webpage at ‘url
f = urllib.urlopen(url)
html_doc = f.read()
#convert into a BeautifulSOup Object
soup = BeautifulSoup(html_doc, ‘html.parser’)
#Remove all nodes which are enclosed in script or
#style tags, otherwise we would be extracting the text
#from inside these nodes, wheras we only want the text
#on the webpage
for elem in soup.findAll([‘script’, ‘style’]):
#extract all the text from the soup object from
#the element tags
text = soup.get_text()
I enclosed the script in a flask server. I need to set this app up as a server and api point which we can query from the extension using Ajax, and for the python app to send back the webpage text to the extension according to the URL sent by the extension.