简体   繁体   English

ValueError:未知的url类型:h; 在urllib2中?

[英]ValueError: unknown url type: h; in urllib2?

Here is part of my code: 这是我的代码的一部分:

import urllib2
def find_all(list1):
    for link1 in list1:
        p1 = urllib2.urlopen(link1)
        s1 = p1.read()
        s2 = s1.find('"ratingValue"')
        start_char = s1.find('>', s2)
        .......

m = 'http://www.tervisetrend.ee/hambaarst-Aleksei-Ratsep-MD18661.aspx'
lm = list(m)
find_all(lm)

When i run it, i have following error: 当我运行它时,出现以下错误:

Traceback (most recent call last):
  File "/home/mike/Downloads/link_code.py", line 70, in <module>
    find_all(lm)
  File "/home/mike/Downloads/link_code.py", line 40, in find_all
    p1 = urllib2.urlopen(link1)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 396, in open
    protocol = req.get_type()
  File "/usr/lib/python2.7/urllib2.py", line 258, in get_type
    raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: h

Why am I having this error and how can I fix that? 为什么会有这个错误,我该如何解决?

Note: i have run this for many times and it didn't give me an error before now. 注意:我已经运行了很多次,在此之前没有给我一个错误。

Thanks. 谢谢。

If you do a print of lm : 如果您打印lm

lm = list(m)
print(lm)
>>> ['h', 't', 't', 'p', ':', etc...]

you will find that you created a list of characters. 您会发现您创建了一个字符列表。

the correct way is: 正确的方法是:

lm = [m]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM