download:【最新更新版】Python分布式爬虫打造搜索引擎
未来是什么时代?是数据时代!数据分析服务、互联网金融,数据建模、自然语言处理、医疗病例分析……越来越多的工作会基于数据来做,而爬虫正是快速获取数据最重要的方式,相比其它语言,Python爬虫更简单、高效。
适合人群及技术储备要求
适合对爬虫感兴趣、想做大数据开发却找不到数据,又不知如何搭建一套稳定可靠的分布式爬虫的同学
想搭建搜索引擎但是不知道如何入手的同学
技术储备要求:
具备一定的原生爬虫基础,了解前端页面,面向对象概念,计算机网络协议和数据库知识
import random 2 if name ==" main ": #四位数字字母考证码的生成 3 checkcode="" #保管考证码的变量 4 for i in range(4): 5 index=random.randrange(0,4) #生成一个0~3中的数 6 if index!=i and index +1 !=i: 7 checkcode +=chr(random.randint(97,122)) # 生成a~z中的一个小写字母 8 elif index +1==i: 9 checkcode +=chr(random.randint(65,90) ) # 生成A~Z中的一个大写字母 10 else: 11 checkcode +=str(random.randint(1,9)) # 数字1-9 12 print(checkcode) 复制代码 输出为:m47A、8wQ9、vugS
2。格式化时间函数
1 def formatTime(longtime): 2 '''格式化时间的函数''' 3 import time 4 return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(longtime))
3。记载显现登录日志实例
复制代码 import time def show_info(): print('''输入提示数字,执行相应操作 0:退出 1:查看登录日志 ''') def write_loginfo(username): """ 将用户名和登录时间写入日志 :param username: 用户名 """ with open('log.txt','a') as f: string = "用户名:{} 登录时间:{}\n".format(username ,time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) f.write(string) def read_loginfo(): """ 读取日志 """ with open('log.txt','r') as f: while True: line = f.readline() if line == '': break # 跳出循环 print(line) # 输出一行内容 if name == " main ":
输入用户名
username = input('请输入用户名:') # 检测用户名 while len(username) < 2 : print('用户名长度应不少于2位') username = input('请输入用户名:') # 输入密码 password = input('请输入密码:') # 检测密码 while len(passw ord) < 6 : print('密码长度应不少于6位') password = input('请输入密码:') print('登录胜利') write_loginfo(username) # 写入日志 show_info() # 提示信息 num = int(input('输入操作数字:')) # 输入数字 while True: if num == 0: print('退出胜利') break elif num == 1: print('查看登录日志') read_loginfo() show_info() num = int(input('输入操作数字:')) else: print('您输入的数字有误') show_info() num = int(input('输入操作数字:'))
3。模仿淘宝客服自动回复 复制代码 1 # 任务2:模仿淘宝客服自动回复 2 3 def find_answer(question): 4 with open('reply.txt','r') as f : 5 while True: 6 line=f.readline() 7 if not line: #也能够为if line=='' 8 break 9 keyword=line.split('|')[0] 10 reply=line.split('|')[1] 11 if keyword in question: 12 return reply 13 return '对不起,没有你想要找的问题' 14 15 if name ==' main ': 16 question=input('请输入想要发问的内容:') 17 while True: 18 if question=='bye': 19 break 20 reply=find_answer(question) 21 if not reply: 22 question=input("小蜜不懂您在说什么,您能够问一些与订单、账户和支付相关的内容(退出请输入bye):") 23 else: 24 print(reply) 25 question=input("您能够问一些与订单、账户和支付相关的内容(退出请输入bye):") 26 print('谢谢,再见!') 27 复制代码 复制代码 4。求最大条约数和最小公倍数 (辗转相除法) 最大条约数:指两个或多个整数共有约数中最大的一个
最小公倍数:两个或多个整数公有的倍数叫做它们的公倍数,其中除0以外最小的一个公倍数就叫做这几个整数的最小公倍数
二者关系:两个数之积=最小公倍数*最大条约数
复制代码 1 a=int(input('输入数字1:')) 2 b=int(input('输入数字2:')) 3 s=a*b 4 while a%b!=0: 5 a,b=b,(a%b) 6 print(a) 7 print(b) 8 else: 9 print(b,'is the maximum common divisor最大条约数') 10 print(s//b,'is the least common multiple,最小公倍数') 复制代码 更相减损法
查看更多关于【最新更新版】Python分布式爬虫打造搜索引擎的详细内容...