Python2.7。在
我确定这是一个愚蠢的问题,但我真的被urlspilt中的类型/属性错误弄糊涂了。在
我试图遍历unicode url的列表,拆分并重新构建它们以删除部分url。在
new_list = []
for line in list_of_links:
urlsplit(line)
new_list.append(line.scheme + '://' + line.netloc + line.path)
返回AttributeError: 'unicode' object has no attribute 'scheme'
将每行编码为utf-8不起作用。str(line).scheme返回'str' object has no attribute 'scheme'
我错过了什么?在
在}命名的元组对象。参见文档here。只有它们具有
line
仍然是str,而字符串没有这些方法。urlparse()
和urlsplit()
分别返回ParseResult
和{scheme
和netloc
属性。要正确使用它们,请将结果存储在变量中,如下所示:相关问题 更多 >
编程相关推荐