美文网首页
爬虫python和正则

爬虫python和正则

作者: JuneZhu_870a | 来源:发表于2018-08-23 09:25 被阅读13次
  1. 爬虫基本


    python包
image.png

打开网页

import urllib.request

#req=urllib.request.Request('http://placekitten.com/g/500/600')
#response = urllib.request.urlopen(req)
response = urllib.request.urlopen('http://placekitten.com/g/500/600')
cat_img = response.read().decode('utf-8')

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

修改header 代理
  1. 正则表达式
re.search(r'FishC','I love FishC.com!')
search方法
image.png

相关文章

网友评论

      本文标题:爬虫python和正则

      本文链接:https://www.haomeiwen.com/subject/rpeyiftx.html