做风险控制和个人征信,需要做数据挖掘,第一步就是要爬到消费记录,当然还有很多其他项包括收货地址 宝贝收藏 快速退款额度 芝麻信用 绑定的手机等等,先要爬到数据才能分析。

淘宝直接请求登录接口不可行,不知道post参数加密规则,(大公司安全就是做得好),用selenium操作浏览器来登录得到driver的cookie,然后requests携带cookie去爬订单。如果全部都由selenium爬取无疑很慢,所以selenium负责登录就行。

上代码。

#coding=utf-8
import time,random,requests,jsonfrom selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesclass Taobao(object):def __init__(self,name,password):self.name=nameself.password=passwordself.login_url='https://login.taobao.com/member/login.jhtml?redirectURL=https%3A%2F%2Fwww.taobao.com%2F'self.order_url='https://buyertrade.taobao.com/trade/itemlist/asyncBought.htm?action=itemlist/BoughtQueryAction&event_submit_do_query=1&_input_charset=utf8'self.num=0self.cost=0def login(self):     ###如果用phantomjs浏览器就用这个# dcap = dict(DesiredCapabilities.PHANTOMJS)   # dcap["phantomjs.page.settings.userAgent"] = ('Mozilla/5.0(WindowsNT6.1;WOW64) AppleWebKit/537.36(KHTML, likeGecko) Chrome/59.0.3071.115Safari/537.36x-requested-with:XMLHttpRequest')#(random.choice(agents))# dcap["phantomjs.page.settings.loadImages"] = True# driver = webdriver.PhantomJS(executable_path='C:\\Python27\\phantomjs.exe',desired_capabilities=dcap)
driver=webdriver.Chrome()driver.get(self.login_url)driver.find_element_by_id('J_Quick2Static').click()WebDriverWait(driver, 30, 0.5).until(EC.presence_of_element_located((By.ID, 'TPL_username_1')))driver.find_element_by_id('TPL_username_1').send_keys(self.name)driver.save_screenshot('1.jpg')                                      ##用phantomjs无界面浏览器最好需要截图driver.find_element_by_id('TPL_password_1').send_keys(self.password)driver.save_screenshot('2.jpg')driver.find_element_by_id('J_SubmitStatic').click()time.sleep(10)driver.save_screenshot('3.jpg')self.cookies={}for dictx in driver.get_cookies():self.cookies[dictx['name']]=dictx['value']driver.quit()def get_orders(self,p,flag):if flag==0:self.login()print self.cookiesdatax={'pageNum':p+1,'pageSize':15,'prePageNo':p,}header = {'origin': 'https://buyertrade.taobao.com',           ###origin和refere一定需要,否则会请求不到订单数据'referer':'https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm','user-agent':'Mozilla/5.0(WindowsNT6.1;WOW64) AppleWebKit/537.36(KHTML, likeGecko) Chrome/59.0.3071.115Safari/537.36x-requested-with:XMLHttpRequest',#'cookie':'miid=387872062667523128; thw=cn;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.....',  ##如果不用浏览器登录,可以在headrs中携带字符串形式的cookie
                  }resp=requests.post(self.order_url,data=datax,cookies=self.cookies,headers=header)#resp=requests.post(self.order_url,data=datax,headers=header)#print resp.content.decode('gbk')orders_dictx = json.loads(resp.content.decode('gbk'))pages=orders_dictx['page']['totalPage']for order in orders_dictx['mainOrders']:self.num+=1self.cost+=float(order['payInfo']['actualFee'])print self.num,' ',order['subOrders'][0]['itemInfo']['title'],'    价格是: ',order['payInfo']['actualFee'],'元 交易状态是:',order['statusInfo']['text'],self.costif flag==0:for p in range(1,pages+1):self.get_orders(p,1)if __name__=="__main__":passtb=Taobao('369xxxx@qq.com','123xxxxxxxx')tb.get_orders(0,0)

运行后爬到的订单。

要爬很多项,已购买宝贝只是其中之一,账号 密码要做成做接口传过来触发爬虫。然后保存各项数据,做数据挖掘用。

根据统计,我在淘宝购物了205次,花费了28613.53元。

转载于:https://www.cnblogs.com/ydf0509/p/7164026.html

淘宝爬取某人的所有购物订单相关推荐

  1. Python实现淘宝爬取——奶粉销售信息爬取及其数据可视化

    简介 双十一刚过,TB的销售额又创下了新高,我也为2000+亿做出了贡献 恰巧买了一袋德运奶粉,味道还不错.我就在想,接触爬虫也有两个多月了,还没有爬过TB这种经典的网站,借着劲头就爬取了一下TB上奶 ...

  2. 将淘宝爬取的数据写入Excel表格

    我们上一篇文章已经获取到淘宝的数据写入了.json文件.现在我们就可以写入Excel表格. 运行结果是这样子的. from selenium.webdriver import Chrome impor ...

  3. 淘宝爬取图片和url

    刚开始爬取了 百度图片和搜狗图片 但是图片不是很多,随后继续爬取淘宝图片,但是淘宝反爬比较厉害 之前的方法不能用 记录可行的 淘宝爬取 利用selenium爬取 https://cloud.tence ...

  4. 淘宝抓取宝贝买家秀核心代码

    #淘宝抓取宝贝买家秀核心代码 def getPhoto(self,*comentlist):try:for comments in comentlist:#print(len(comentlist)) ...

  5. 淘宝商城,亚洲最大网上购物网站

    淘宝商城,亚洲最大网上购物网站--淘宝网打造的在线B2C购物平台(B2C,Business to Customer).在淘宝商城购物,享受100%正品保障.7天退换货.提供发票的服务. Q1>按 ...

  6. 淘宝API获取购买到的商品订单列表

    淘宝/天猫获取购买到的商品订单列表 API 返回值说明 buyer_order_list-获取购买到的商品订单列表 公共参数 请求地址: https://console.open.onebound.c ...

  7. 淘宝/天猫获取卖出的商品订单列表API接口,店铺订单API接口,店铺订单详情API接口

    一.淘宝/天猫获取卖出的商品订单列表API接口,店铺订单API接口,店铺订单详情API接口代码如下: 1.公共参数: 名称 类型 必须 描述 key String 是 调用key(必须以GET方式拼接 ...

  8. 淘宝API 获取购买到的商品订单详情

    淘宝API_buyer_order_detail - 获取购买到的商品订单详情 Result Object: { "take_baby": null, "payment_ ...

  9. 淘宝开店第四天应该多少订单?淘宝订单数量如何提升?

    随着淘宝平台的不断壮大,越来越多的人开始在淘宝开店了,我们在淘宝开店了以后需要做的事情有很多.比如说去运营推广淘宝店铺,另外对于淘宝店铺来说,订单数量非常的重要,一般第4天有多少订单比较好? 淘宝开店 ...

最新文章

  1. pandas常用函数说明及速查表
  2. 聚合Aggregation与合成Composition
  3. QQ WINDWOS 8 METRO版使用体验
  4. POJ-2386-Lake Counting
  5. springmvc的执行流程_springmvc执行流程
  6. 对使用CodeSmith模板生成NHibernate的代码的分析
  7. Java EE陷阱#1:忽略@Singleton的默认锁定
  8. c 程序中的注释相当于空白字符_Python专题 | (三)注释、变量与输出
  9. Struts 2 Spring Hibernate三大框架的执行流程以及原理
  10. mysql批量用trim限定_mybatis中批量更新sql语句,trim、foreach标签,varchar定义理解
  11. touch拦截监听_Android - requestDisallowInterceptTouchEvent() 阻止父层的View截获touch事件(事件处理机制)...
  12. 无法启动windows audio服务,错误提示126.
  13. 【C语言编程】实现猜数字游戏
  14. j2ee02 集合框架
  15. 任意多边形的最大内切圆算法
  16. 苹果应用提审与NAT64
  17. 视频编码fmpeg 常用命令汇总
  18. MapReduce学习笔记(二)——Mapper、Reducer和Driver
  19. vue的history模式,页面刷新404,以及引入得第三方插件或者JS路径错误的解决办法
  20. 跨部门不配合工作_跨部门对接很难?同事不配合你?来,我教你怎么搞定!

热门文章

  1. 《设计模式详解》行为型模式 - 解释器模式
  2. 【恋上数据结构】递归(函数调用过程、斐波那契数列、上楼梯、汉诺塔、递归转非递归、尾调用)
  3. 【微型计算机原理与接口技术】80X86微处理器发展与内部结构
  4. JavaScript闭包初相识
  5. 小程序入门学习13--云函数与数据库02
  6. [转]Ubuntu terminator 无法打开解决方案
  7. 报表引擎API开发入门—带参程序数据集
  8. 通过F12控制台退订育碧(Ubisoft)邮件
  9. 中仪股份管道机器人_中仪股份携带管道机器人再次出发美国,携手2018年WEFTEC欢度国庆...
  10. php 把查询数据转json格式,php将从数据库查询到的数据转化为json格式,并写入json文件中...