Skip to content

Instantly share code, notes, and snippets.

@awentzonline
Created April 10, 2014 19:38
Show Gist options
  • Select an option

  • Save awentzonline/10415560 to your computer and use it in GitHub Desktop.

Select an option

Save awentzonline/10415560 to your computer and use it in GitHub Desktop.
ROBOT READS YOU A WEB FRAGMENT
import subprocess
import sys
import lxml.html
import requests
if __name__ == '__main__':
url, selector = sys.argv[-2:]
response = requests.get(url)
doc = lxml.html.fromstring(response.content)
text = []
for elm in doc.cssselect(selector):
text.append(elm.text_content().encode('utf-8'))
try:
subprocess.call(['say', '. '.join(text)])
except KeyboardInterrupt:
pass
@awentzonline
Copy link
Copy Markdown
Author

Save it as wwwblab.py and then:

python wwwblab.py "http://www.cnn.com/2014/04/10/wor/asia/malaysia-airlines-plane/index.html?hpt=hp_t1" ".cnn_strycntntlft p"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment