Beispiel #1
0
    def __token_get(self):
        # 获取首页cookies
        urls = [
            'https://www.amazon.com/gp/goldbox?ref_=nav_cs_gb_azl',
            'https://www.amazon.com/b/ref=gc_surl_giftcards?node=2238192011',
            'https://www.amazon.com/ref=nav_logo',
            'https://www.amazon.com/gp/help/customer/display.html?nodeId=508510&ref_=nav_cs_help'
            'https://www.amazon.com/b/?_encoding=UTF8&ld=AZUSSOA-sell&node=12766669011&ref_=nav_cs_sell',
            'https://www.amazon.com/Outlet/b/?ie=UTF8&node=517808&ref_=sv_subnav_goldbox_3'
        ]
        url = choice(urls)
        self.request(url=url)
        tools.sleep(3)
        self.__change_cidy()
        if not self.session.cookies.get('ubid-main'):
            self.logger.warning('[%s]: %s Token Failed %s' %
                                (tools.current_time(), self.__zip_code, url))
            return None
        # 显示成功日志
        if self.__debug:
            self.logger.warning('[%s]: Token Success.' % tools.current_time())

        cookies = self.session.cookies
        cookies = self.dict_from_cookiejar(cookies)
        return cookies
Beispiel #2
0
    def run(self):
        web = Process(target=self.web)
        web.start()

        cookies = Process(target=self.cookies)
        cookies.start()

        goods = Process(target=self.goods)
        tools.sleep(60 * 5)  #等侍5分钟后启动 这几分钟可添加数据
        goods.start()
Beispiel #3
0
 def __proxies_set(self, is_set_proxy=False):
     """设置代理"""
     if self.__proxy_api and is_set_proxy:
         tools.sleep(2)
         ip = self.request(url=self.__proxy_api)
         if ip:
             self.session.proxies = {'http':ip, 'https':ip}
         else:
             self.logger.warning('[%s]: Get Porxies Failed!' % tools.current_time())
             self.session.proxies={}
     else: self.session.proxies = {}
Beispiel #4
0
 def __cookies_up(self):
     """
     更新Cookies
     :return:
     """
     token = sqlite.execute('select id,row from cookies limit 1').fetchone()
     if token:
         self.__token_id = token[0]
         cookies = json.loads(unquote(token[1]))
         self.session.cookies = self.cookiejar_from_dict(cookies)
         return True
     self.logger.warning('[%s]: 数据库中Cookie为空,等待600秒...'%tools.current_time())
     tools.sleep(600)
     return False
Beispiel #5
0
 def goods(self):
     n = 1  #计数
     i = [6, 9, 20, 11, 15]  # 为求随机
     api = 'http://127.0.0.1:1015/get?m=mina998'
     api = 'http://198.35.45.110:1015/get?m=mina998'
     obj = Goods(debug=debug, proxy_api=api)
     while True:
         if n % choice(i) == 0: is_proxy = False
         else: is_proxy = True
         # 下次运行时间(秒)
         if debug: exe = 600
         else: exe = tools.next_time_stamp() - tools.time_stamp_now(True)
         if obj.get(is_proxy) == 'ok': tools.sleep(exe)
         n += 1
Beispiel #6
0
 def __info_get(self):
     # 组装url
     query = '/?m=%s' % self.__seller if self.__seller else ''
     url = 'https://www.amazon.com/dp/%s%s' % (self.__asin, query)
     # 获取Html
     html = self.request(url=url)
     if not html: return False
     img, bsr, pre, sto = self.__item_(html)
     if not (pre and sto):
         self.logger.warning('[%s]: 排名:%s, 价格:%s, 库存:%s  %s' % (tools.current_time(), bsr, pre, sto, url))
         return False
     # 显示成功日志
     proxy =  '没有使用代理' if not self.session.proxies else self.session.proxies['http']
     if self.__debug: self.logger.warning('[%s]: 排名:%s, 价格:%s, 库存:%s' % (proxy, bsr, pre, sto))
     return dict(bsr=bsr, price=pre, stock=sto, img=img, uptime=tools.current_time('%Y-%m-%d %H:%M:%S'), aid=self.__aid)
Beispiel #7
0
    def __asin_get(self):
        """
        获取Listing信息
        :return:
        """
        row = sqlite.execute('select id,asin,seller from listing where status =0 order by random() limit 5').fetchone()

        if row:
            self.__aid = row[0]
            self.__asin = row[1]
            self.__seller = row[2]
            return True
        self.logger.warning('[%s]: 本轮完成.等待中......' % tools.current_time())
        self.__status_up()
        return False
Beispiel #8
0
    def __item_(self, html):
        #
        sid = tools.xpath_one('//input[@id="session-id"][@name="session-id"]/@value', html)
        #
        oid = tools.xpath_one('//input[@id="offerListingID"][@name="offerListingID"]/@value', html)
        # 产品图片
        img = tools.re_one(r'colorImages\'.*?(https.*?)"', html)
        # 获取BSR排名
        bsr = tools.re_one(r"#([\d,]+)\sin.*See top 100.*</a>\)", html)
        # 获取产品价格
        pre = tools.re_one(r'id=\"priceblock_ourprice.*?>\$([\d.]+)<', html)
        # 获取产品库存
        sto = tools.re_one(r'Only (\d+?) left in stock - order soon.', html)
        if not sto: sto = self.__stock_(sid, oid)

        return img, bsr, pre, sto
Beispiel #9
0
 def cookies(self):
     while True:
         tools.sleep(5)
         obj = Cookies(zip=choice(zips), debug=debug)
         obj.get()