{
	"0": {
		"0": {
			"unit_index": 0,
			"line_task_name": "카페 카테고리별 카페아이디 추출",
			"check_box": true
		},
		"1": {
			"unit_index": 1,
			"combo_search_site": "https://section.cafe.naver.com/ca-fe/home/themes/1?type=ac",
			"check_auto_paste": false
		},
		"2": {
			"unit_index": 11,
			"plain_scripts": "# 카테고리별 카페아이디 추출 변수 초기화\r\nself.PAGENO = 1\nself.cafe_list= list()\r\n\r\nbase_path, _= os.path.splitext(self.recipe_file)\r\n_, base_file= os.path.split(self.recipe_file)\r\nif not os.path.exists(base_path):\r\n    os.makedirs(base_path)\r\n\r\ncategory_pos = 0\ncategory_list= list()\nextracted_cafe_count = 0\nfor ii in range(25):\n    category_list.append(f\"https://section.cafe.naver.com/ca-fe/home/themes/{ii+1}?type=ac\")\nprint('categories', category_pos, len(category_list))",
			"dynamic_plain_scripts_vscroll": 16
		},
		"3": {
			"unit_index": 9,
			"line_time_break": "1",
			"line_time_script": "# 카테고리 이동",
			"check_endof_task": false
		},
		"4": {
			"unit_index": 11,
			"plain_scripts": "from selenium.webdriver.support.ui import WebDriverWait\r\nfrom selenium.webdriver.support import expected_conditions as EC\r\nfrom selenium.webdriver.common.by import By\r\nfrom selenium.common.exceptions import TimeoutException\r\ncategory_url = self.ul[2].category_list[self.ul[2].category_pos]\ntry:\r\n    print(category_url)\r\n    self.BROWSER.get(category_url)\r\nexcept TimeoutException as ex:\r\n    print(ex.Message)\r\n    self.CURNO = 8\r\nelse:\r\n    WebDriverWait(self.BROWSER, 10).until(EC.element_to_be_clickable((By.XPATH, '/html/body')))\r\n",
			"dynamic_plain_scripts_vscroll": 12
		},
		"5": {
			"unit_index": 9,
			"line_time_break": "0",
			"line_time_script": "# 카페 목록 추출 15개",
			"check_endof_task": false
		},
		"6": {
			"unit_index": 11,
			"plain_scripts": "cafe_elements = self.BROWSER.find_elements_by_xpath('//a[@class=\"cafe_item_wrap\"]')\r\nprint('cafe_elements', len(cafe_elements))\r\nif len(cafe_elements) == 0:\r\n    self.CURNO = 10\r\ncafe_elements_pos = 0\r\nprint(self.ul[2].category_pos, len(self.ul[2].category_list), self.BROWSER.find_elements_by_xpath('//li[@class=\"on\"]')[0].text.split('\\n')[0], len(self.cafe_list))",
			"dynamic_plain_scripts_vscroll": 5
		},
		"7": {
			"unit_index": 9,
			"line_time_break": "0",
			"line_time_script": "# 세부 사이트 페이지로 이동하여 ID와 URL 수집",
			"check_endof_task": false
		},
		"8": {
			"unit_index": 11,
			"plain_scripts": "cafe_dict= dict()\ncafe_dict['cafe_title']= self.ul[6].cafe_elements[self.ul[6].cafe_elements_pos].text.split('\\n')[0].strip()\r\n\r\n# 사이트 페이지로 이동\r\nfrom selenium.webdriver.support.ui import WebDriverWait\r\nfrom selenium.webdriver.support import expected_conditions as EC\r\nfrom selenium.webdriver.common.by import By\r\nfrom selenium.common.exceptions import TimeoutException\r\n\r\ntry:\r\n    self.ul[6].cafe_elements[self.ul[6].cafe_elements_pos].click()\r\nexcept TimeoutException as ex:\r\n    print(ex.Message)\r\nelse:    \r\n    WebDriverWait(self.BROWSER, 10).until(EC.element_to_be_clickable((By.XPATH, '/html/body')))\r\n    time.sleep(1.0)\r\n    self.BROWSER.switch_to.window(self.BROWSER.window_handles[-1])\n    href = self.BROWSER.current_url\n    cafe_dict['cafe_id']= href.split('/')[-1]\n    cafe_dict['cafe_url'] = href\n    if cafe_dict not in self.cafe_list:\r\n        print(cafe_dict)\n        self.cafe_list.append(cafe_dict)\r\n        \r\nif len(self.BROWSER.window_handles) > 1:\r\n    self.BROWSER.close()\r\n    self.BROWSER.switch_to.window(self.BROWSER.window_handles[-1])\r\n",
			"dynamic_plain_scripts_vscroll": 23
		},
		"9": {
			"unit_index": 9,
			"line_time_break": "0",
			"line_time_script": "# 다음 사이트가 있는 경우 반복 실행",
			"check_endof_task": false
		},
		"10": {
			"unit_index": 11,
			"plain_scripts": "self.ul[6].cafe_elements_pos += 1\r\nif self.ul[6].cafe_elements_pos < len(self.ul[6].cafe_elements):\r\n    self.CURNO = 6\r\nprint('self.CURNO', self.CURNO, self.ul[6].cafe_elements_pos, len(self.ul[6].cafe_elements))",
			"dynamic_plain_scripts_vscroll": 4
		},
		"11": {
			"unit_index": 9,
			"line_time_break": "1",
			"line_time_script": "# 다음 페이지 이동",
			"check_endof_task": false
		},
		"12": {
			"unit_index": 11,
			"plain_scripts": "pages= self.BROWSER.find_elements_by_xpath('//button[@aria-pressed=\"false\"]')\nprint('pages', len(pages))\nfor indx, page in enumerate(pages):\n    if self.PAGENO < int(page.text):\n        self.PAGENO = int(page.text)\n        break\r\nif  self.PAGENO > int(page.text):\r\n    page = self.BROWSER.find_element_by_xpath('//button[@class=\"btn type_next\"]')\r\n    \n# 페이지 번호가 바뀌었거나 추가로 카페가 수집이 된경우 다음페이지 수집        \r\nif self.ul[2].extracted_cafe_count < len(self.cafe_list):\n    self.ul[2].extracted_cafe_count= len(self.cafe_list)\n    page.click()\n    self.CURNO = 5\nprint('CURNO', self.CURNO, 'PAGENO', self.PAGENO, page.text, self.ul[2].extracted_cafe_count, len(self.cafe_list))",
			"dynamic_plain_scripts_vscroll": 16
		},
		"13": {
			"unit_index": 9,
			"line_time_break": "1",
			"line_time_script": "# 카테고리 반복 작업",
			"check_endof_task": false
		},
		"14": {
			"unit_index": 11,
			"plain_scripts": "self.ul[2].category_pos += 1\nif self.ul[2].category_pos < len(self.ul[2].category_list):\n    self.CURNO = 3\n    self.PAGENO = 1\nprint(self.CURNO, self.PAGENO, '카테고리', self.ul[2].category_pos, len(self.ul[2].category_list))",
			"dynamic_plain_scripts_vscroll": 6
		},
		"15": {
			"unit_index": 9,
			"line_time_break": "1",
			"line_time_script": "# 수집된 카페 목록 저장",
			"check_endof_task": false
		},
		"16": {
			"unit_index": 11,
			"plain_scripts": "# .json 파일로 저장\r\nimport json, csv\r\njson_file= f\"{self.ul[2].base_path}\\\\{self.ul[2].base_file.split('.')[0]}_result.json\"\nwith open(json_file, 'w', encoding='utf8') as fw:\r\n    json.dump(self.cafe_list, fw, ensure_ascii=False, indent=4)\r\n\r\n# .csv 파일로 저장 \r\ncsv_file= f\"{self.ul[2].base_path}\\\\{self.ul[2].base_file.split('.')[0]}_result.csv\"\nwith open(csv_file, 'w', encoding='utf-8-sig') as csvfile:\n    writer= csv.DictWriter(csvfile, fieldnames=['cafe_id', 'cafe_url', 'cafe_title'])\n    writer.writeheader()\n    writer.writerows(self.cafe_list)",
			"dynamic_plain_scripts_vscroll": 13
		},
		"17": {
			"unit_index": 9,
			"line_time_break": "1",
			"line_time_script": "# End of shell",
			"check_endof_task": true
		},
		"18": {
			"unit_index": 11,
			"plain_scripts": "self.ul[2].category_pos = 0\r\nprint(self.ul[2].category_pos)\r\nprint(self.ul[2].category_list[self.ul[2].category_pos])\r\nself.CURNO = 5\r\nself.PAGENO = 741\r\n\r\n# self.BROWSER.switch_to.window(self.BROWSER.window_handles[-1])",
			"dynamic_plain_scripts_vscroll": 16
		},
		"19": {
			"unit_index": 11,
			"plain_scripts": "from selenium.common.exceptions import TimeoutException\r\nprint(self.BROWSER.current_url)\r\nprint(self.ul[8].cafe_dict)\r\ntry:\r\n    self.BROWSER.refresh()\r\nexcept TimeoutException as ex:\r\n   print(ex.Message)\r\n   ",
			"dynamic_plain_scripts_vscroll": 12
		}
	}
}