Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from huaisha1224:main #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions Get-JDCookie.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = "Huaisha2049"
import asyncio
from random import random
from socket import timeout
Expand Down Expand Up @@ -27,13 +28,18 @@ def find_cookie(cookies):
async def main():
"""使用pyppeteer库来登录京东、并获取cookie
"""
print('请在弹出的网页中登录账号、推荐使用账户短信验证码的形式登录。')
browser = await launch(headless=False, dumpio=True, autoClose=False,
args=['--no-sandbox', '--window-size=1000,800', '--disable-infobars']) # 进入有头模式
context = await browser.createIncognitoBrowserContext() # 隐身模式

# 关闭默认打开的第一个标签页
pages = await browser.pages()
if pages:
await pages[0].close()

page = await context.newPage() # 打开新的标签页
await page.setViewport({'width': 1000, 'height': 800}) # 页面大小一致
await page.goto('https://home.m.jd.com',{'timeout': 1000*60}) # 访问主页、增加超时解决Navigation Timeout Exceeded: 30000 ms exceeded报错
await page.goto('https://home.m.jd.com/myJd/home.action',{'timeout': 1000*60}) # 访问主页、增加超时解决Navigation Timeout Exceeded: 30000 ms exceeded报错

await page.waitFor(1000)
elm = await page.waitForXPath('//*[@id="myHeader"]',timeout=0) # 通过判断用户头像是否存在来确定登录状态
Expand All @@ -50,4 +56,25 @@ async def main():


if __name__== "__main__":
aaa = """

   へ     /|
  /\7    ∠_/
  / │   / /
 │ Z _,< /   /`ヽ
 │     ヽ   /  〉
  Y     `  /  /
 ●  ●  〈  /
 ()  へ    | \〈
  > _  ィ  │ //
  / へ   / <| \\
  ヽ_  (_/  │//
  7       |/
  >―r ̄ ̄`―_

使用说明:在弹出的网页中登录账号、推荐使用账户短信验证码的形式登录
问题反馈:https://github.com/huaisha1224
作者:怀沙2049
"""
print(aaa)
asyncio.get_event_loop().run_until_complete(main()) #调用
Binary file modified exe/Get-JDCookie.exe
Binary file not shown.