大大怪将军33 发表于 2020-4-22 18:03:07

小小爬虫问题

urllib.error.URLError:<urllopen error no host given>
这个错误怎么解决?{:10_279:}{:10_279:}

liuzhengyuan 发表于 2020-4-22 18:18:23

网址有没有打错?
请把完整代码发上来

大大怪将军33 发表于 2020-4-22 18:20:06

liuzhengyuan 发表于 2020-4-22 18:18
网址有没有打错?
请把完整代码发上来

import urllib.request
reponse = urllib.request.urlopen("http:\\placekitten.com\g\500\600")
html = response.read()

with open("c:\\a\\html.jpg",'wb') as f:
    f.write(html)

liuzhengyuan 发表于 2020-4-22 18:35:37

是正斜杠,不是反斜杠(这是一个成功的代码)
import urllib.request

response = urllib.request.urlopen('http://placekitten.com/g/200/300')
cat_img = response.read()

with open('cat_200_300.jpg', 'wb') as f:
    f.write(cat_img)

大大怪将军33 发表于 2020-4-22 18:40:22

谢谢大佬
页: [1]
查看完整版本: 小小爬虫问题