python

爬虫新手,请问这个unknown url type是什么意思,感觉输入URL正确且有加http:// ,用的是美丽汤

讨论数量: 2
Jason990420

How to describe your issue

  1. Summarize the problem

    • Include details about your goal
    • Describe expected and actual results
    • Include any error messages
  2. Describe what you’ve tried

    • Show what you’ve tried and tell us what you found (on this site or elsewhere) and why it didn’t meet your needs. You can get better answers when you provide research.
  3. Show some code

    • When appropriate, share the minimum amount of code others need to reproduce your problem (also called a minimum, reproducible example)
3年前 评论
Jason990420

应该是你的代码有问题, 你又什么都没提 ...

>>> url = 'http://py4e-data.dr-chuck.net/comments_845667.html'
>>> html = urllib.request.urlopen(url).read()
>>>
>>> url = ''
>>> html = urllib.request.urlopen(url).read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Software\Python\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Software\Python\lib\urllib\request.py", line 510, in open
    req = Request(fullurl, data)
  File "C:\Software\Python\lib\urllib\request.py", line 328, in __init__
    self.full_url = url
  File "C:\Software\Python\lib\urllib\request.py", line 354, in full_url
    self._parse()
  File "C:\Software\Python\lib\urllib\request.py", line 383, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: ''
>>>
>>> url = 'py4e-data.dr-chuck.net/comments_845667.html'
>>> html = urllib.request.urlopen(url).read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Software\Python\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Software\Python\lib\urllib\request.py", line 510, in open
    req = Request(fullurl, data)
  File "C:\Software\Python\lib\urllib\request.py", line 328, in __init__
    self.full_url = url
  File "C:\Software\Python\lib\urllib\request.py", line 354, in full_url
    self._parse()
  File "C:\Software\Python\lib\urllib\request.py", line 383, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'py4e-data.dr-chuck.net/comments_845667.html'
>>>
3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!