学习爬虫入门2,count反爬虫思路

发布时间 2023-06-15 21:07:19作者: 墨柠C

浏览网页的过程

1.输入网址

2.浏览器向DNS服务商发起请求

3.找到对应服务器

4.服务器解析请求

5.服务器处理最终请求发回去

6.浏览器解析返回数据

7.展示给用户

爬虫策略

广度优先   深度优先   聚焦爬虫

BFS 从根节点开始 沿着树的宽度

深度优先 DFS 尽可能深的搜索树的分支 然后再返回起点

 爬取实习僧招聘不完全如

Import requests

from bs4 import BeautifulSoup
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Applewebkit/537.36 (KHTML, like Gecko}
def detial_url(url):
html=requests.get(url ,headers=headers )

soup=BeautifulSoup(html.text,'lxml')

title=soup.title

print(title)
defcraw1():

for page in range(1,2):

html=requests.get('https://www.shixiseng.com/interns?page=()&keyword=python' .format(page),

headers=headers)

soup=Beautifulsoup(html.text,'lxml')

offers=soup.select('.intern-wrap.intern-item')

for offer in offers:

url=offer.select('.f-l.intern-detail job a')[0['href']

detial url(url)

过滤title 只需要后续加.text

获取可以直接复制标签名字 后续【0】.text

cutom_font(自定义字体)反爬虫 

首先你要先获取字体映射关系

照例先获取文本,然后.encode('utf-8')

找出破解代码,如\Xef

repalce(b'\Xef,b'2')

.decode()

Scrapy库

针对每个URL,scheduler__downloader__Spider

soup.select()筛选元素,返回的是list 标签名不加修饰,class面前加. ID前面加#