1.如何提升爬取数据的效率(异步爬虫)
- 使用框架
- 线程池,多任务的异步协程
- 分布式
2.在爬虫中为什么需要是用selenium?selenium和爬虫之间的关联是什么?
- 爬取动态加载的数据
- 模拟登录
3.列举你所用过的python内置装饰器,至少2个。
@property
@staticmethod
@classmethod
4.通过列表生成式,生成这样一个结果列表[1, 9, 25, 49, 81]。(2分)
[x * x for x in range(1, 11) if x%2 != 0]
5 将name变量对应的值变大写,并输出结果
name = " gouguoQ"
v = name.upper()
print (v)
6 将name变量对应的值变成小写,并输出结果
name = " gouguoQ"
v = name.lower()
print (v)
7 请输出name变量对应的值的第二个字符?
name = " gouguoQ"
v = name[2]
print (v)
8 请输出name变量对应的值的前三个字符
name = " gouguoQ"
v = name[0:3]
print (v)
9 请输出name变量对应值的后2个字符
name = " gouguoQ"
v = name[-2:]
print (v)
10 获取子序列,仅不包含最后一个字符,如:woaini则获取woain root则获取roo
name = " gouguoQ"
print (name[0:-1])
5.*args和**args这两种参数的区别是什么?(2分)
*args: 表示元组
**args: 表示字典
11.JSON模块中dumps()和loads()函数的作用分别是什么?(2分)
Dumps: 将一个字典转化为json字符串
Loads: 将一个json字符串转化为字典
12.如何提高爬取效率?
爬虫下载慢主要原因是阻塞等待发往网站的请求和网站返回
1,采用异步与多线程,扩大电脑的cpu利用率;
2,采用消息队列模式
3,提高带宽
13.request请求方式中的post、get有什么区别
GET一般用于获取/查询资源信息,而POST一般用于更新资源信息
get是在url中传递数据,数据放在请求头中,post是在请求体中传递数据
get安全性非常低,post安全性较高,但是get执行效率却比Post方法好
如果感到对你有帮助麻烦动手帮忙点个赞噢~谢谢啦~
附加题---------------------------------------------------------------------------------------------------
购物车程序:
需求:
1. 启动程序,让用户输入工资,然后打印商品列表;
2.允许用户根据商品编号或者商品名字购买商品;
3.用户输入商品列表后检测余额是否足够,够就直接扣款,不够就提醒;
4.用户可以一直购买商品,也可以直接退出,退出后打印已购买商品和余额;
balance=0
shoplist=[{'identifier':1,'apple':5},{'identifier':2,'banana':4},{'identifier':3,'cake':20},{'identifier':4,'shoe':99},{'identifier':5,'diamond':200}]
shoplist1,shoplist2,shoplist3=[],[],[]
shop_cart={}for i in shoplist:
k=i
del k['identifier']
shoplist1.append(k)#提取出商品名称和单价
shoplist2.append(list(k.keys())[0])#单独提取出商品名称
shoplist3.append(list(k.values())[0])#单独提取出商品单价
salary=int(input('please input your salary:'))print("the selective menu are as follwed:")print(shoplist)print('please select your want goods:')while 1:
want=input() #可以输入商品的数字编号或者商品名字
if want.isdigit() and int(want) in range(1,len(shoplist)+1):
want=int(want)
goods=shoplist2[want - 1]
price=shoplist3[want - 1]
elif want in shoplist2:
p = shoplist2.index(want)
goods=want
price=shoplist3[p]
else:
print("the goods is not existed, please input again")
continue
print('you has selected:',goods, ',its price:', price)
quantity = int(input('please input the quantity of the goods:'))
if salary>=quantity*price:
salary-=quantity*price
balance+=quantity*price
shop_cart[goods]={price:quantity}
else:
print('sorry,you can not afford it')
print("you can input any word to keep shopping or input 'N'to end shopping")
s=input()
if s!='N':
continue
else:
breakprint('your shoppinglist is as follows:')print(shop_cart)print('your shopping consuption is:',balance)
本文汇总了Python爬虫相关的编程题目,包括提升爬取效率的方法、selenium的使用场景、Python内置装饰器示例、JSON操作及爬虫效率优化等。还提供了一个购物车程序,模拟购买流程,检查余额并扣款。
1214

被折叠的 条评论
为什么被折叠?



