Loading

爬虫介绍

介绍

爬虫指爬取网络资源,如:视频,音乐,资料等

python写爬虫,代码简洁,其他语言也可以做爬虫

  • 善意的爬虫,不破坏被爬取的网站的资源(正常访问,一般频率不高,不窃取用户隐私)
  • 恶意的爬虫,影响网站的正常运营(抢票,秒杀,疯狂solo网站资源造成网站岩机)

robots.txt协议:
君子协议。规定了网站中哪些数据可以被爬虫爬取哪些数据不可以被爬取。(只是一个协议,不会拦截爬虫)

示例

from urllib.request import urlopen

url = 'https://baidu.com'
resp = urlopen(url)
# b'<!DOCTYPE html><!--STATUS OK--><html><head><meta...'表示字节串(字节串以b开头)
# resp.read().decode:将字节串解码为字符串
content = resp.read().decode("utf-8")
print(content)

with open('百度搜索.html', 'w', encoding="utf-8") as f:
    f.write(content)
posted @ 2024-12-17 16:54  一只大学生  阅读(28)  评论(0)    收藏  举报