Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

這個例外處理是在做什麼的? #29

Open
linroex opened this issue Feb 6, 2016 · 0 comments
Open

這個例外處理是在做什麼的? #29

linroex opened this issue Feb 6, 2016 · 0 comments
Assignees

Comments

@linroex
Copy link
Collaborator

linroex commented Feb 6, 2016

try:
    #uer "str" ,  because list not use 
    topic = str(topic_split.findall(data)).replace('<h1 class=\"headline\">', '').replace('</h1>', '').replace('\\u3000', '', 20).replace('╱', '', 10).replace('[', '', 10).replace(']', '',10)
    author = str(author_split.findall(data)).replace('<span class=\"provider org\">', '').replace('</span>', '').replace('[', '', 10).replace(']', '',10)
    date = str(date_split.findall(data)).replace('>', '<', 10).split('<')[2]      #this is so trouble,  it is ["",  "<abbr title = ...",  "date",  "</abbr>",  ""],  so is data[2]
    text = str(text_split.findall(data)).replace('<p class=\"first\">', '').replace('</p>', '', 100).replace(' ', '', 100).replace('<p>', '', 100).replace('[', '', 10).replace(']', '',10).replace('\',\'', '', 10)

    #deal with date
    if '下' in date:
        date = date.replace('下午', '')
        try:
            date = datetime.strptime(date, '%Y年%m月%d日 %H:%M') + timedelta(hours = 12)
        except:
            date = datetime.strptime(date, '%Y年%m月%d日 %H:%M') + timedelta(days = 1, hours = -12)
    else:
        date = date.replace('上午', '')
        date = datetime.strptime(date, '%Y年%m月%d日 %H:%M') 


    self.data.append(News(topic, author, date, text).toJson())

    print('第', len(self.data), '則新聞已擷取完')
except:
    pass

為什麼 except 會直接 pass?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants