多线程之小米商店APP爬虫
2020-01-14 19:33
423 查看
#今日目标 **多线程之小米商店APP爬虫** 爬取小米商店所有社交APP ``` import requests import time from threading import Thread from queue import Queue import json class XiaoAppSpider(object): def __init__(self): self.url='http://app.mi.com/categotyAllListApi?page={}&categoryId=2&pageSize=30' self.headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36X-Requested-With: XMLHttpRequest'} self.url_queue=Queue() self.n=0 #url队列 def url_in(self): for i in range(67): url=self.url.format(i) #入队列 self.url_queue.put(url) #线程事件函数 def get_data(self): while True: if self.url_queue.empty(): break #get地址,请求+解析+保存 url=self.url_queue.get() html=requests.get(url=url,headers=self.headers).content.decode('utf-8') html=json.loads(html) #with open('xiao.json','a') as f: #app_dict={} for app in html['data']: app_name=app['displayName'] app_link='http://app.mi.com/details?'+app['packageName'] print(app_name,app_link) self.n +=1 #主函数 def main(self): #url入队列 self.url_in() #创建多线程 t_list=[] for i in range (5): t=Thread(target=self.get_data) t_list.append(t) t.start() for i in t_list: i.join() print('应用数量:',self.n) if __name__ == '__main__': start=time.time() spider=XiaoAppSpider() spider.main() end=time.time() print('执行时间为{}'.format(end-start)) ```
转载于:https://www.cnblogs.com/cxiaolong/p/11273314.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Python 爬虫工程师必学 App数据抓取实战
- 微信小程序商店域名由wxapp.dreawer.com永久更换为:store.dreawer.com
- python爬虫---多线程爬取腾讯招聘数据【晋级版】
- 爬虫学习记录-多线程爬取图片
- Android进阶#(3/12)保证APP流畅的关键因素——多线程_Android中的消息机制
- Java网络爬虫(八)--使用多线程进行百度图片的抓取
- Java多线程爬虫爬取京东商品信息
- python 多线程 爬虫
- 多线程爬虫遇到的一些问题
- #7、多线程爬虫
- python 广度多线程爬虫
- 多线程爬虫遇到问题求大神指教
- 抢先式多线程网络爬虫spider在智能搜索引擎中的实现
- python爬虫多线程进程
- phantomjs 与多线程爬虫
- (嗅事百科)多线程爬虫
- 重新想象 Windows 8 Store Apps (70) - 其它: 文件压缩和解压缩, 与 Windows 商店相关的操作, app 与 web, 几个 Core 的应用, 页面的生命周期和程序的生命周期
- 爬虫笔记——多线程爬取斗图网表情包(threading)
- python多线程爬虫:亚马逊价格
- configure SharePoint Store settings(避免用户在网上商店购买或下载App )