__new\uuu()缺少1个必需的位置参数,具体取决于刮取的url

2024-04-18 01:36:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个奇怪的错误,我会尽量简化我的问题。 我有一个简单的函数,它用漂亮的汤刮出一个url并返回一个列表。 然后,我在文件中pickle该列表,因此我setrecursionlimit(10000)以避免递归错误。在那之前,一切都很好。在

但是当我试图解开我的列表时,我有一个错误:

Traceback (most recent call last):
  File ".\scrap_index.py", line 86, in <module>
    data_file = pickle.load(data)
TypeError: __new__() missing 1 required positional argument: 'name'

我的职能是:

^{pr2}$

为了测试,我尝试了不同的url。 有了这个网址,一切都很好:

url_ok = 'https://www.boursorama.com/bourse/'

但有了这个,我有个错误:

url_not_ok = 'https://www.boursorama.com/bourse/actions'

以及测试代码:

import pickle
import sys

sys.setrecursionlimit(10000)

scrap_list = scrap_function(url_not_ok)

with open('test_saving.pkl', 'wb') as data:
    pickle.dump(scrap_list, data, protocol=2)

with open('test_saving.pkl', 'rb') as data:
    data_file = pickle.load(data)

print(data_file)

Tags: httpscomurl列表datawww错误load
1条回答
网友
1楼 · 发布于 2024-04-18 01:36:26

This状态

If some class objects have extra arguments in the new constructor , pickle fail to serialize it.

这可能会导致beautifulsoap中的问题here

class NavigableString(unicode, PageElement):
    def __new__(cls, value):

This answer状态相同。在

作为一种解决方案,不要存储整个对象,而可能只存储页面的源代码,如here。在

相关问题 更多 >

    热门问题