Skip to content

Commit

Permalink
temp cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
moyada committed May 19, 2024
1 parent 79737c4 commit 8f4e560
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
'--disable-blink-features=AutomationControlled'
]

cks = [{'name': '', 'value': 'douyin.com', 'domain': 'www.douyin.com', 'path': '/video', 'expires': -1, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'device_web_cpu_core', 'value': '8', 'domain': 'www.douyin.com', 'path': '/video', 'expires': -1, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'device_web_memory_size', 'value': '8', 'domain': 'www.douyin.com', 'path': '/video', 'expires': -1, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'ttwid', 'value': '1%7CBaOuINUvKIDzpYaxE9kiGZDiPNvjkCzeq0Opbdl5VIk%7C1716110266%7Ce4314ba7773b6ce02d308eb1d05f0d259aa8fc52a95d8b2c8f417826c9dc2014', 'domain': '.iesdouyin.com', 'path': '/', 'expires': 1747214266.836294, 'httpOnly': True, 'secure': False, 'sameSite': 'Lax'}, {'name': '__ac_nonce', 'value': '06649c3ba0024ddf07136', 'domain': 'www.douyin.com', 'path': '/', 'expires': 1716112066.968196, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': '__ac_signature', 'value': '_02B4Z6wo00f01lokgZAAAIDCmYf-lRRpOWZaBIUAAPDPf6', 'domain': 'www.douyin.com', 'path': '/', 'expires': 1747646267, 'httpOnly': False, 'secure': True, 'sameSite': 'None'}, {'name': 'ttwid', 'value': '1%7CuCmgL7j4f44mWkHwC8EJ4iFp3ApyvEaVeaJj9XE8tyQ%7C1716110267%7Cb6317aa1a0cdb8ae5d3ad58d6f36ad7eeef085e8e2fafe0bc721ac7ae944340a', 'domain': '.douyin.com', 'path': '/', 'expires': 1747214267.365654, 'httpOnly': True, 'secure': False, 'sameSite': 'Lax'}, {'name': 'IsDouyinActive', 'value': 'true', 'domain': '.douyin.com', 'path': '/', 'expires': 1716715068.032838, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'home_can_add_dy_2_desktop', 'value': '%220%22', 'domain': '.douyin.com', 'path': '/', 'expires': 1716715068.033804, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'dy_swidth', 'value': '1280', 'domain': 'www.douyin.com', 'path': '/', 'expires': 1716715068, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'dy_sheight', 'value': '720', 'domain': 'www.douyin.com', 'path': '/', 'expires': 1716715068, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'stream_recommend_feed_params', 'value': '%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1280%2C%5C%22screen_height%5C%22%3A720%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A150%7D%22', 'domain': '.douyin.com', 'path': '/', 'expires': 1716715068.038004, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'strategyABtestKey', 'value': '%221716110268.177%22', 'domain': '.douyin.com', 'path': '/', 'expires': 1716715068.17778, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'csrf_session_id', 'value': '5e1f3d33adf5c0883052d57bcfef7c11', 'domain': 'www.douyin.com', 'path': '/', 'expires': -1, 'httpOnly': False, 'secure': True, 'sameSite': 'None'}, {'name': 'FORCE_LOGIN', 'value': '%7B%22videoConsumedRemainSeconds%22%3A180%7D', 'domain': '.douyin.com', 'path': '/', 'expires': 1716715068.422286, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 's_v_web_id', 'value': 'verify_lwdbqthk_y54Yk72i_crn9_4nuZ_A7Ep_7maLEOojitjI', 'domain': 'www.douyin.com', 'path': '/', 'expires': 1721294268, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'passport_csrf_token', 'value': '74a651d7ecb7ec478c7b9780e854296f', 'domain': '.douyin.com', 'path': '/', 'expires': 1721294268.496005, 'httpOnly': False, 'secure': True, 'sameSite': 'None'}, {'name': 'passport_csrf_token_default', 'value': '74a651d7ecb7ec478c7b9780e854296f', 'domain': '.douyin.com', 'path': '/', 'expires': 1721294268.496039, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'bd_ticket_guard_client_data', 'value': 'eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCRktIN3J4cXlUdzErL2tsUG9ReWVuQmpCTVo0SndVMWp5emtZTzNmRGpGQ2lyZ3I2ZFFuMEhjeWFYSWtaZTQxeElMamVvbFZUd1VlcG9tQnMzSHprSWM9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D', 'domain': '.douyin.com', 'path': '/', 'expires': 1721294268.796166, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'bd_ticket_guard_client_web_domain', 'value': '2', 'domain': '.douyin.com', 'path': '/', 'expires': 1721294268.796263, 'httpOnly': False, 'secure': False, 'sameSite': 'Lax'}, {'name': 'msToken', 'value': 'pHD31bx0jhrQmCl2bRjG_k-UN4daiPfOz8z8Ldg0v_BAoaDnuqhEbrwVsTXFFY4pgTAHgtXXeVrjQSrSWrhEO8vj4sNtx31BZNPglZ5c', 'domain': '.douyin.com', 'path': '/', 'expires': 1716715070.120579, 'httpOnly': False, 'secure': True, 'sameSite': 'None'}]


class PageContext:
browser = None
Expand All @@ -39,6 +41,17 @@ def __init__(self, p: Playwright):
self.browser = p.chromium.launch(headless=os.environ['headless'] == "1", args=args, timeout=20000)
self.context = self.browser.new_context()
self.page = self.context.new_page()
self.context.add_cookies(cks)

def sync(self):
print("sync")
try:
cks = self.context.cookies()
print(cks)
except Exception as e:
print(e)
pass


def close(self):
try:
Expand Down
1 change: 1 addition & 0 deletions browser/douyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_info(cls, url: str) -> any:
p.page.wait_for_timeout(100)

path = get_path(p.page.url)
# p.sync()
p.close()

if path == "/":
Expand Down

0 comments on commit 8f4e560

Please sign in to comment.