Python爬虫,定时轮询网址

CSDN博客爬虫示例
本文介绍了一个使用Python进行CSDN博客文章爬取的示例代码,通过urllib.request模块获取网页内容,展示了如何批量访问多个链接并读取页面信息。代码中包含了时间间隔设置以避免频繁请求。

参考代码如下:

# -*- coding:utf-8 -*-

import datetime

import time

import urllib.request



url = { '0' : 'https://blog.csdn.net/Fighting_Boom/article/details/88732537',	# Linux通用 源码方式安装OpenCV3

	'1' : 'https://blog.csdn.net/Fighting_Boom/article/details/82185415',	# 树莓派3B+ 安装官方原版系统

	'2' : 'https://blog.csdn.net/Fighting_Boom/article/details/87969477',	# 百度云资料备份

	'3' : 'https://blog.csdn.net/Fighting_Boom/article/details/90256610',	# cheese 打开摄像头黑屏

	'4' : 'https://blog.csdn.net/Fighting_Boom/article/details/88786412',	# vim 设置主题行号

	'5' : 'https://blog.csdn.net/Fighting_Boom/article/details/82215362',	# 树莓派源码方式安装OpenCV

	'6' : 'https://blog.csdn.net/Fighting_Boom/article/details/82737108',	# keil4 keil5 兼容安装破解

	'7' : 'https://blog.csdn.net/Fighting_Boom/article/details/81534927',	# 15指纹识别

	'8' : 'https://blog.csdn.net/Fighting_Boom/article/details/81584897',	# pycharm 安装破解教程

	'9' : 'https://blog.csdn.net/Fighting_Boom/article/details/83315486',	# ESP8266 贝壳物联

	'10': 'https://blog.csdn.net/Fighting_Boom/article/details/90607435',	# ASCII码表

	'11': 'https://blog.csdn.net/Fighting_Boom/article/details/90690630',	# ubuntu shell 命令行关机卡死

	'12': 'https://blog.csdn.net/Fighting_Boom/article/details/90697499',	# ubuntu ping不通win10

	'13': 'https://blog.csdn.net/Fighting_Boom/article/details/90747150',	# ubuntu 无法联网 目标主机不可达

	'14': 'https://blog.csdn.net/Fighting_Boom/article/details/91417400',	# windows 搭建SVN服务器

	'15': 'https://blog.csdn.net/Fighting_Boom/article/details/91983972',	# linux UDP通信 sendto错误

	'16': 'https://blog.csdn.net/Fighting_Boom/article/details/91990142',	# ubuntu wifi 图标 扇形





}





def getHtml(url):

	page = urllib.request.urlopen(url)

	html = page.read()

	html = html.decode('utf-8')

	return html




def main():

	for i in url:

		getHtml( url[i] )

		time.sleep(4)

#	time.sleep(47)




while(1):

	main()

上边需要加上UTF-8的说明,不然会出现错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FightingBoom

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值