爬虫学习,第一课就被卡死了,找不到问题所在
代码import urllib.request
req==urllib.request.Request('http://placekitten.com/800/800')
response=urllib.request.urlopen(req)
cat_img=response.read()
with open('cat_800_800.img','wb') as f:
f.write(cat_img)
问题===
Traceback (most recent call last):
File "G:/网站爬虫8.2.py", line 2, in <module>
req==urllib.request.Request('http://placekitten.com/800/800')
NameError: name 'req' is not defined
req==urllib.request.Request('http://placekitten.com/800/800') 把red==ur..这里的双等号改为单等号试试 本帖最后由 临时号 于 2022-8-2 19:01 编辑
req==urllib.request.Request('http://placekitten.com/800/800')这里写了两个==,改成一个=
还有,图片文件的后缀名不是img,改成png
import urllib.request
req=urllib.request.Request('http://placekitten.com/800/800')
response=urllib.request.urlopen(req)
cat_img=response.read()
with open('cat_800_800.png','wb') as f:
f.write(cat_img) req==urllib.request.Request('http://placekitten.com/800/800')
这里把双等号改成单等号试试怎么样 应该是这样吧
import urllib.request
req = urllib.request.Request('http://placekitten.com/800/800')
response = urllib.request.urlopen(req)
cat_jpg = response.read()
with open('cat_800_800.jpg','wb') as f:
f.write(cat_jpg) 双等于是真的等于,单等于是附值 学到了
页:
[1]