Skip to content

Instantly share code, notes, and snippets.

@rrggrr
Last active January 11, 2016 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrggrr/a6a77cd369de9435453c to your computer and use it in GitHub Desktop.
Save rrggrr/a6a77cd369de9435453c to your computer and use it in GitHub Desktop.
Parse Drudge Report Headline
# FOR USE WITH TEXTBAR ( www.richsomerfield.com ) OR BIT BAR (https://github.com/matryer/bitbar)
# /usr/local/bin/python /./Users/<u>/drudge.py
import requests
from bs4 import BeautifulSoup
from lxml import etree
headline = "..."
try:
with requests.Session() as session:
session.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36'}
response = session.get('http://www.drudgereport.com')
html = response.text
soup = BeautifulSoup(html)
section = soup.find("font", size="+7")
headline = section.text
except Exception as err:
print(err)
try:
print(headline)
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment