Python Selenium: 使用列表作为 JSON 字典的键
selects_attributes = {}\nselects = driver.find_elements(By.CLASS_NAME, "select-trigger")\nfor element in selects:\n key = [element.location['x'], element.location['y']]\n selects_attributes[key] = {"text": element.text, "id": element.id}\nprint(selects_attributes)\n\ntime.sleep(5)\ndriver.quit()\nwith open("page_data.json", "w", encoding='utf-8') as f:\n data = {"inputs": inputs_attributes, "texts": text_attributes, "selects": selects_attributes}\n f.write(json.dumps(data, ensure_ascii=False))
原文地址: https://www.cveoy.top/t/topic/qagr 著作权归作者所有。请勿转载和采集!