Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在try中存储并继续执行,Python除外_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

在try中存储并继续执行,Python除外

在try中存储并继续执行,Python除外,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,我想存储错误消息并继续执行,但当我使用异常e:存储错误消息时,我无法继续执行。如果URL没有获取HTTP URL,函数将停止执行,如果 url="www.boomlive.in/fact-file/did-the-race-to-5g-cause-the-coronavirus-outbreak-7404" 我的代码是 def twitter_链接(url): twitter_title=[] response=requests.get(url) soup=BeautifulSoup(resp

我想存储错误消息并继续执行,但当我使用异常e:存储错误消息时,我无法继续执行。如果URL没有获取HTTP URL,函数将停止执行,如果

url="www.boomlive.in/fact-file/did-the-race-to-5g-cause-the-coronavirus-outbreak-7404"
我的代码是

def twitter_链接(url):
twitter_title=[]
response=requests.get(url)
soup=BeautifulSoup(response.text,“html.parser”)
因为我在汤里。找到所有的(“p”):
尝试:
对于i.find_all中的a(“a”,href=True):
如果在[“href”]中出现“twitter”:
x=a[“href”]
twitter_title.append(x)
例外情况除外,如e:
twitter_title.append(str(e))
继续
返回twitter\u标题

我的异常输出是函数将URL存储在列表twitter_title中,如果有错误,则存储错误消息并继续执行

函数停止执行,因为异常是由
请求引发的。get(URL)
并且该调用不在try块内。

异常的代码在哪里?默认情况下,如果没有明确的
返回
中断
语句,python中的错误处理将继续执行。“www.boomlive.in…”不是URL
requests.get()
将使用此参数失败。它应该以“http://”开头@BruceWayne我添加了code@pciunkiewicz如何解决这类问题