web 爬虫初体验

#爬虫
#python 如何访问互联网
#url 一般格式 protocol://hostname[;port]/path/[;parameters]
#[?query]#fragment
#lib
import urllib.request
response=urllib.request.urlopen("http://www.fishc.com")
html =response.read()
html= html.decode("utf-8")

print(html)

导入 urllib.request,打开网页读取,编码规则utf-8

import urllib.request
response=urllib.request.urlopen("http://placekitten.com/g/500/600")
cat_img=response.read()
#req=urllib.request.Request("http://placekitten.com/g/500/600")
#response =urllib.request.urlopen(req)




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

这段代码是二进制位把一张图片存储起来。

response.geturl() 

'http://placekitten.com/g/500/600'

print(response.info())

Date: Thu, 23 Jun 2016 11:42:12 GMT
Content-Type: image/jpeg
Content-Length: 26590
Connection: close
Set-Cookie: __cfduid=de6449c3832066b6394c536b5dcff0db81466682132; expires=Fri, 23-Jun-17 11:42:12 GMT; path=/; domain=.placekitten.com; HttpOnly
Accept-Ranges: bytes
X-Powered-By: PleskLin
Access-Control-Allow-Origin: *
Cache-Control: public
Expires: Thu, 31 Dec 2020 20:00:00 GMT
Server: cloudflare-nginx
CF-RAY: 2b77ace311ea22f4-LAX

 response.getcode()

200 表示成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值