python 爬虫基本

一、爬虫主要是实现对网页上自己喜欢的资源的爬取。

1、python自带的urllib

html = urllib.request.urlopen('网站').read()

2、第三方库requests

resp = requests.get('网站').text

如果返回的结果没有保存且没有报错,那么说明你访问的网站有反爬虫机制一般处理方法

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}
resp = requests.get('网址', headers=headers)
resp_test = resp.text
resp.close()  // 关闭连接

 二、解析方式

1、正则表达式

模块re

2、bs4

posted on 2021-07-21 21:22  缘随风烬  阅读(30)  评论(0编辑  收藏  举报