Support for cookies added

NYT needs them
master
pictuga 2013-02-25 20:53:59 +01:00
parent d6179a734f
commit d39604c453
1 changed files with 6 additions and 2 deletions

8
morss
View File

@ -1,9 +1,11 @@
#! /usr/bin/env python2.7 #! /usr/bin/env python2.7
import sys import sys
import os import os
from os.path import expanduser
from lxml import etree from lxml import etree
import urllib2 import urllib2
from os.path import expanduser import urllib
from cookielib import CookieJar
def log(str): def log(str):
if (len(sys.argv) == 3): if (len(sys.argv) == 3):
@ -39,7 +41,9 @@ for item in items:
desc.text = open(cached, 'r').read() desc.text = open(cached, 'r').read()
else: else:
try: try:
data = urllib2.urlopen(link).read() cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
data = opener.open(link).read()
html = etree.HTML(data) html = etree.HTML(data)
match = html.xpath(node) match = html.xpath(node)