如何解决如何修改异常代码并防止终止?
我遇到了以下代码的问题。我尝试抓取一组通常具有相同结构但有时会发生异常的页面,我正在努力如何在代码中考虑它。目前,代码搜索括在 'strong' 标签中的某些文本,但有时我要查找的文本被括在 'p' 标签中。如何修改代码以便考虑这一点?
我面临的另一个问题是,如果没有找到任何匹配的文本,代码将停止执行,而不是跳转到下一页,即继续。任何想法如何处理这个?
#pull strong tags from speech script section
for i in script:
if i.find('strong') is not None:
g = "strong"
else:
g = 0
bj.append(g)
#Create list of index position of strong tags
for j in range(len(bj)):
if bj[j] == 'strong':
indices.append(j)
#Create list of text from speech script
for k in script:
x = k.text.strip()
convo.append(x)
#Create script ID & Participant ID
script_id = counter2
part_id = counter3
#Create index objects to find positions of speech & participant sections
conf_part_index = convo[convo.index('Conference Call Participants')+1:convo.index('Operator')]
try:
speech_index = indices[0:indices.index(convo.index('Question-and-Answer Session'))]
except:
try:
speech_index = indices[0:indices.index(convo.index('Question-And-Answer Session'))]
except:
try:
speech_index = indices[0:indices.index(convo.index('Questions-and-Answer Session'))]
except:
speech_index = indices[0:indices.index(convo.index('Question-and-Answers Session'))]
try:
QA_index = indices[indices.index(convo.index('Question-and-Answer Session'))+1:]
except:
try:
QA_index = indices[indices.index(convo.index('Question-And-Answer Session'))+1:]
except:
try:
QA_index = indices[indices.index(convo.index('Questions-and-Answer Session'))+1:]
except:
QA_index = indices[indices.index(convo.index('Question-and-Answers Session'))+1:]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。