以面向过程的思维,第一个入门爬虫。运用模块: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 =