selenium需要在执行js脚本 但是js里需要python变量,我这样写非常不优雅,更好方法?

注意datetime.datetime.now().strftime('%Y-%m-')

def get_shopify_month_data(driver):
    script = """
    fetch("https://gw.lingxingerp.com/cepf-statistics/api/sales/analysisGoodsSummary",{"headers":{"accept":"application/json, text/plain, */*","accept-language":"zh-CN,zh;q=0.9","ak-client-type":"web","auth-token":"83e1H82FeAa3JCh0hFaEHdvzXcZ2aUqDk8FgM4ojQrdUn0RA60FNwnZsVUP+h+nj5CiB2zBrvYoFk1aUAgF0VNb7t5LnV8jg5X2PkxLAK/pOO6/yNuqn7qaEgMn6VpCulUD/OymltXo8LKPNtmtIi3aibFmn4/wS","content-type":"application/json;charset=UTF-8","sec-ch-ua":"\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"macOS\"","sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"cross-site","x-ak-company-id":"90136221130850816"},"referrer":"https://erp.lingxing.com/","referrerPolicy":"strict-origin-when-cross-origin","body":"{\"platformCodes\":[10002],\"goodsDimension\":5,\"siteCodes\":[],\"storeIds\":[\"110240161579679744\"],\"timeDimension\":3,\"startTime\":\"
  """+datetime.datetime.now().strftime('%Y-%m-')+"""\",\"endTime\":\"
"""+datetime.datetime.now().strftime('%Y-%m-%d')+"""
  \",\"currencyCode\":\"CNY\",\"searchType\":3,\"searchSingleValue\":\"\",\"searchMultiValue\":[],\"typeIds\":[],\"brandIds\":[],\"sortField\":\"firstQuantity\",\"sortType\":\"desc\",\"length\":20,\"offset\":0,\"req_time_sequence\":\"/cepf-statistics/api/sales/analysisGoodsSummary$$2\"}","method":"POST","mode":"cors","credentials":"omit"}).then(function(response){return response.json()}).then(function(myJson){console.log(myJson)}).catch(function(e){return{}})
    """
    return driver.execute_script(script)
阅读 797
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏