用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - python代码库

亚马逊登录

2019-08-02 作者:云代码会员举报

[python]代码库

import asyncio
import time
from pyppeteer.launcher import launch
import random
js1='''
  ()=>{
  Object.defineProperty(navigator, 'webdriver', {
    get: () => false,
  });
  }
'''
js2='''
  () => {
   window.navigator.chrome = {
    runtime: {},
    // etc.
  };
  }
'''
js3='''() => {
  const originalQuery = window.navigator.permissions.query;
  return window.navigator.permissions.query = (parameters) => (
    parameters.name === 'notifications' ?
      Promise.resolve({ state: Notification.permission }) :
      originalQuery(parameters)
  );
  }
'''
js4='''
() => {
  Object.defineProperty(navigator, 'plugins', {
    get: () => [1, 2, 3, 4, 5],
  })
  }
'''
js5='''
() => {
  Object.defineProperty(navigator, 'languages', {
    get: () => ['en-US', 'en'],
  })
  }
'''

 
async def main(username, pwd, url):
    try:
      browser = await launch({
                      'headless': False,
                      'dumpio': True,
                      "ignoreHTTPSErrors":True,
                      'args': [
                          '--disable-extensions',
                          '--hide-scrollbars',
                          '--disable-bundled-ppapi-flash',
                          '--mute-audio',
                          '--no-sandbox',
                          '--disable-setuid-sandbox',
                          '--disable-gpu',
                          # "--proxy-server=http://127.0.0.1:8080"
                      ],
                  })
      pages = await browser.pages()
      page=pages[0]
      # page = await browser.newPage()
      await page.setUserAgent(
          'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299')

      await page.goto(url,timeout=0,waitUntil=["networkidle2"])
      
      await page.evaluate(js1)
      await page.evaluate(js2)
      await page.evaluate(js3)
      await page.evaluate(js4)
      await page.evaluate(js5)
      # await page.evaluate(js6)
      # await asyncio.sleep(2)
      await page.waitFor(2000)
      await page.click("[name=rememberMe]")
      print("填写密码")
      await page.type('#ap_email', username,{'delay':50})
      await page.type('#ap_password', pwd,{'delay':30})
      print("填写密码完成")
      await page.waitFor(5000)
      await page.click("[type=submit]")
      # await asyncio.sleep(5)
      print("点击完成")
      # await asyncio.sleep(5)
      await page.waitFor(7000)

      cks=await page.cookies()
      cookies={}
      for ck in cks:
          cookies[ck["name"]]=ck["value"]
      print(cookies)
      try:
        await page.close()
      except:
        pass
      try:
        await browser.close()
      except:
        pass
      return False
    except Exception as e:
        print(e)
        try:
          await page.close()
        except:
          pass
        try:
          await browser.close()
        except:
          pass
        raise ArithmeticError


if __name__ == '__main__':
    username="fff"
    pwd="ffff"
    url="https://sellercentral.amazon.com/gp/homepage.html"
    loop = asyncio.get_event_loop()
    # num=0
    # while True:
    #   num+=1
    #   if num>8:
    #     raise ArithmeticError
    #   try:
    p=loop.run_until_complete(main(username, pwd, url))
      # except Exception as e:
      #   print(e)
      #   print("重新尝试")
      # else:
      #   if p:
      #     break


分享到:
更多

网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。