zzzzzzzzzzzz_test_defined_playwright_chrome.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # from datetime import datetime, timezone
  2. # from playwright.async_api import async_playwright, Playwright
  3. # from playwright.sync_api import expect
  4. from playwright.async_api import Playwright, async_playwright, expect
  5. import random
  6. import time
  7. import datetime
  8. import asyncio
  9. import pathlib
  10. import shutil
  11. old_print = print
  12. def timestamped_print(*args, **kwargs):
  13. old_print(datetime.datetime.utcnow().replace(
  14. microsecond=0), *args, **kwargs)
  15. print = timestamped_print
  16. print('\n'*5)
  17. print(f"{'{:<6}'.format('enter')} ----------------NOTE-----------NOTE---------------")
  18. def makedirpath( folder):
  19. pathlib.Path(folder).mkdir(exist_ok=True)
  20. def rmfolder( folder):
  21. if pathlib.Path(folder).exists():
  22. shutil.rmtree(folder)
  23. # Python中windows路径的3种写法
  24. # 可以是以下这样写:
  25. utc_timeto = int(time.time())
  26. utc_timefrom = int(utc_timeto - 17*24*3600)
  27. utc_timeto = int(utc_timeto + 2*24*3600)
  28. async def do_some_thing(playwright ):
  29. # browser = playwright.chromium.launch(headless=True)
  30. context = await playwright.chromium.launch_persistent_context(user_data_dir=USER_DIR_PATH, accept_downloads=True, headless=False)
  31. # context = await playwright.firefox.launch_persistent_context(user_data_dir=USER_DIR_PATH, accept_downloads=True, headless=False)
  32. # context = browser.new_context()
  33. context.set_default_timeout(9000)
  34. # context = await browser.new_context()
  35. arr_page = [None]*2
  36. arr_page[0] = await context.new_page()
  37. page = arr_page[0]
  38. await arr_page[0].goto(
  39. "https://www.defined.fi/sol/A9KLSS9modWzMc1A189c6HXwy1QkgUupun9TPJZkhmaw?maker=3RTD4pdo5fJ1pu1jAXRAD2Lzxyx4PHLzo2F6M5mP7LGZ&cache=b8081&quoteToken=token1" , timeout=100000)
  40. # cur_arr_str_dalaoAddress =[15]
  41. print(context.pages)
  42. await page.wait_for_timeout(100000)
  43. time.sleep(5.5)
  44. await page.close()
  45. await context.close()
  46. async def get_onedriver_swapactivities( ):
  47. async with async_playwright() as playwright:
  48. # playwright = Playwright().start()
  49. await do_some_thing(playwright )
  50. async def main():
  51. print("enter main()")
  52. await get_onedriver_swapactivities( )
  53. # USER_DIR_PATH = "./browsercookie_path"
  54. USER_DIR_PATH = baseclass.browsercookie_path
  55. makedirpath(USER_DIR_PATH)
  56. asyncio.run(main())
  57. # main()
  58. print(f"{'{:<6}'.format('END')} ----------------NOTE-----------NOTE---------------")