import datetime
import time

from selenium import webdriver
import pymongo
from selenium.webdriver.common.by import By

db_storage = pymongo.MongoClient('mongodb://114.115.221.202:27017/', username='admin', password='ZZsn@9988').ZZSN[
    '天眼查登录信息']
url = 'https://www.tianyancha.com/'

def create_driver():
    path = r'D:\soft\msedgedriver.exe'

    # options = webdriver.EdgeOptions()
    options = {
        "browserName": "MicrosoftEdge",
        "ms:edgeOptions": {
            "extensions": [], "args": ["--start-maximized"]  # 添加最大化窗口运作参数
        }
    }

    driver = webdriver.Edge(executable_path=path, capabilities=options)
    return driver
if __name__ == "__main__":
    name = input('所属用户:')
    driver = create_driver()
    driver.get(url)
    time.sleep(60)

    cookies = driver.get_cookies()
    # print(driver.get_cookies())
    # 要存储的数据
    create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    fenghaoTime = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')
    data = {
        'name': name,
        'cookies': cookies,
        'createTime': create_time,
        'fenghaoTime': fenghaoTime,
        'updateTime': create_time,
    }

    # 插入数据
    result = db_storage.insert_one(data)

    # 打印插入的数据的 ID
    print(result.inserted_id)