From ae00abcdb240e498fff7993d7fc2e83392739505 Mon Sep 17 00:00:00 2001 From: tianyu Date: Sat, 11 Jul 2015 09:59:34 +0800 Subject: [PATCH] fix crash --- u2helper/u2.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/u2helper/u2.py b/u2helper/u2.py index eb714e4..d29d34b 100644 --- a/u2helper/u2.py +++ b/u2helper/u2.py @@ -54,17 +54,20 @@ for td, table in itertools.izip(td_list, table_list): info_r = requests.get(info_url + str(u2torrent.id), cookies=cookies) - info_soup = BeautifulSoup(info_r.text) + try: + info_soup = BeautifulSoup(info_r.text) - info_name = info_soup.find("span", {'class': 'title'}, text="[name]").parent.find("span", {'class': 'value'}) - u2torrent.folder = info_name.text + info_name = info_soup.find("span", {'class': 'title'}, text="[name]").parent.find("span", {'class': 'value'}) + u2torrent.folder = info_name.text - u2torrent.name = u2torrent.title.split('][')[0].replace('[', '') + u2torrent.name = u2torrent.title.split('][')[0].replace('[', '') - print u2torrent.name + " : " + u2torrent.folder + print u2torrent.name + " : " + u2torrent.folder - torrents.append(json.JSONDecoder().decode(u2torrent.json())) - count += 1 + torrents.append(json.JSONDecoder().decode(u2torrent.json())) + count += 1 + except AttributeError: + print "Fetch folder name failed: " + u2torrent.title time.sleep(3) torrents_dict["count"] = count