入门爬虫(函数封装)-Python

这篇博客介绍了作者的首个Python爬虫项目,采用requests和re模块,通过解析URL获取网页源码,使用正则表达式过滤信息,并简单讲述了爬虫的基本步骤:请求网页、提取数据、下载信息、数据清洗和存储。尽管没有使用bs4和函数封装,但展示了爬虫的基础乐趣。
摘要由CSDN通过智能技术生成

以面向过程的思维,第一个入门爬虫。运用模块:requests,os,re。

第一个爬虫,仅体验爬虫乐趣。所以指定访问url,没有采用bs4模块,没有函数封装,亦没有编写为对象。日后会对本脚本改进。仅仅是分享第一个简单爬虫的乐趣XD。

思路为:1.解析url(requests模块)    2.得到源码text    3.正则过滤text(re模块)    4.下载信息    5.清洗信息    6.信息储存

import requests
import re
import os

def url2text(url):
	temp_url = url
	temp_rsp = requests.get(temp_url)
	temp_rsp.encoding = 'utf-8'
	temp_tex = temp_rsp.text
	return temp_tex
	
def save_path(path,title):
	temp_path = path + title
	if not os.path.exists(temp_path):
		os.mkdir(temp_path)
	os.chdir(temp_path)

def chap_item_get(url_list):
	c_url = []
	c_tit =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值