我从一个.csv文件中读取URL,并试图解析它们。为什么当我在函数urlparse(...)
中显式地放置链接时,我只能在scheme和netloc中得到正确的值,请参见变量o2
,而在urlparse
中给出newsource
时却得不到正确的值
for line in file:
source = str(line.split(",")[2])
print("ORIGINAL URL: \n" + source)
newsource = source.replace('"',"")
print("REMOVING QUOTES: \n" + newsource)
newsource.strip
print("STRIPPING SPACES: \n" + newsource + "\n")
o = urlparse(newsource)
print("RESULT PARSING: " + str(o) + "\n")
o2 = urlparse("http://nl.aldi.be/aldi_vlees_609.html")
print("RESULT MANUAL PARSING: " + str(o2) + "\n")
我可以从失败的解析中看出,您有一个前导空格字符,这将导致与您相同的问题:
此行不起任何作用:
你可能想要:
相关问题 更多 >
编程相关推荐