How to use get_chrome method in Selene

Best Python code snippet using selene_python

INSTs.py

Source:INSTs.py Github

copy

Full Screen

...118# 宜蘭縣公共圖書館 ILCCB V OK119def ILCCB(ISBN):120 sheet = ggSheet()121 worksheet = sheet.get_worksheet(0)122 driver = get_chrome()123 gg = webpac_gov_crawler(124 driver,125 '宜蘭縣公共圖書館',126 'https://webpac.ilccb.gov.tw/',127 ISBN128 )129 driver.close()130 worksheet.append_rows(gg.values.tolist())131 return gg132# 桃園市立圖書館 TYPL V OK133def TYPL(ISBN):134 sheet = ggSheet()135 worksheet = sheet.get_worksheet(0)136 driver = get_chrome()137 gg = webpac_gov_crawler(138 driver,139 '桃園市立圖書館',140 'https://webpac.typl.gov.tw/',141 ISBN142 )143 driver.close()144 worksheet.append_rows(gg.values.tolist())145 return gg146# 高雄市立圖書館 KSML V OK147def KSML(ISBN):148 sheet = ggSheet()149 worksheet = sheet.get_worksheet(0)150 driver = get_chrome()151 gg = webpac_gov_crawler(152 driver,153 '高雄市立圖書館',154 'https://webpacx.ksml.edu.tw/',155 ISBN156 )157 driver.close()158 worksheet.append_rows(gg.values.tolist())159 return gg160# 屏東縣公共圖書館 PTPL V OK161def PTPL(ISBN):162 sheet = ggSheet()163 worksheet = sheet.get_worksheet(0)164 driver = get_chrome()165 gg = webpac_gov_crawler(166 driver,167 '屏東縣公共圖書館',168 'https://library.pthg.gov.tw/',169 ISBN170 )171 driver.close()172 worksheet.append_rows(gg.values.tolist())173 return gg174# 花蓮縣公共圖書館 HLPL V175def HLPL(ISBN):176 sheet = ggSheet()177 worksheet = sheet.get_worksheet(0)178 driver = get_chrome()179 gg = webpac_gov_crawler(180 driver,181 '花蓮縣公共圖書館',182 'https://center.hccc.gov.tw/',183 ISBN184 )185 driver.close()186 worksheet.append_rows(gg.values.tolist())187 return gg188# 澎湖縣公共圖書館 PHPL V189def PHPL(ISBN):190 sheet = ggSheet()191 worksheet = sheet.get_worksheet(0)192 driver = get_chrome()193 gg = webpac_gov_crawler(194 driver,195 '澎湖縣公共圖書館',196 'https://webpac.phlib.nat.gov.tw/',197 ISBN198 )199 driver.close()200 worksheet.append_rows(gg.values.tolist())201 return gg202# 國立雲林科技大學 NYUST V203def NYUST(ISBN):204 sheet = ggSheet()205 worksheet = sheet.get_worksheet(0)206 driver = get_chrome()207 gg = webpac_gov_crawler(208 driver,209 '國立雲林科技大學',210 'https://www.libwebpac.yuntech.edu.tw/',211 ISBN212 )213 driver.close()214 worksheet.append_rows(gg.values.tolist())215 return gg216# 國家電影及視聽文化中心 TFAI V217def TFAI(ISBN):218 sheet = ggSheet()219 worksheet = sheet.get_worksheet(0)220 driver = get_chrome()221 gg = webpac_gov_crawler(222 driver,223 '國家電影及視聽文化中心',224 'https://lib.tfi.org.tw/',225 ISBN226 )227 driver.close()228 worksheet.append_rows(gg.values.tolist())229 return gg230# -----------------------------------------jsp系列-----------------------------------------------------231# webpac_jsp_crawler()232# 佛光|經國學院|宜大|中華|北基督|宏國德霖|嘉藥|臺北市|臺藝大|北市大|北醫|北商大|新竹市|新竹縣|苗栗縣233# 育達|仁德醫專|景文|致理|萬能|健行|明新|空大|中國科大|中教大|臺體|東海|靜宜|僑光|彰師234# 雲林縣|嘉義市|嘉義縣|南華|遠東|正修|美和|臺東|臺東縣|金門|金門縣235# 佛光大學 FGU V236def FGU(ISBN):237 sheet = ggSheet()238 worksheet = sheet.get_worksheet(0)239 driver = get_chrome()240 gg = webpac_jsp_crawler(241 driver,242 '佛光大學',243 "http://libils.fgu.edu.tw/webpacIndex.jsp",244 ISBN245 )246 driver.close()247 worksheet.append_rows(gg.values.tolist())248 return gg249# 經國管理暨健康學院 CKU V250def CKU(ISBN):251 sheet = ggSheet()252 worksheet = sheet.get_worksheet(0)253 driver = get_chrome()254 gg = webpac_jsp_crawler(255 driver,256 '經國管理暨健康學院',257 "http://203.64.136.248/webpacIndex.jsp",258 ISBN259 )260 driver.close()261 worksheet.append_rows(gg.values.tolist())262 return gg263# 國立宜蘭大學 NIU V264def NIU(ISBN):265 sheet = ggSheet()266 worksheet = sheet.get_worksheet(0)267 driver = get_chrome()268 gg = webpac_jsp_crawler(269 driver,270 '國立宜蘭大學',271 "https://lib.niu.edu.tw/webpacIndex.jsp",272 ISBN273 )274 driver.close()275 worksheet.append_rows(gg.values.tolist())276 return gg277# 中華科技大學 CUST V278def CUST(ISBN):279 sheet = ggSheet()280 worksheet = sheet.get_worksheet(0)281 driver = get_chrome()282 gg = webpac_jsp_crawler(283 driver,284 '中華科技大學',285 "http://192.192.231.232/bookDetail.do?id=260965&nowid=3&resid=188809854",286 ISBN287 )288 driver.close()289 worksheet.append_rows(gg.values.tolist())290 return gg291# 臺北基督學院 CCT V292def CCT(ISBN):293 sheet = ggSheet()294 worksheet = sheet.get_worksheet(0)295 driver = get_chrome()296 gg = webpac_jsp_crawler(297 driver,298 '臺北基督學院',299 "http://webpac.cct.edu.tw/webpacIndex.jsp",300 ISBN301 )302 driver.close()303 worksheet.append_rows(gg.values.tolist())304 return gg305# 宏國德霖科技大學 HDUT V306def HDUT(ISBN):307 sheet = ggSheet()308 worksheet = sheet.get_worksheet(0)309 driver = get_chrome()310 gg = webpac_jsp_crawler(311 driver,312 '宏國德霖科技大學',313 "http://210.60.142.23/webpacIndex.jsp",314 ISBN315 )316 driver.close()317 worksheet.append_rows(gg.values.tolist())318 return gg319# 嘉南藥理大學 CNU V320def CNU(ISBN):321 sheet = ggSheet()322 worksheet = sheet.get_worksheet(0)323 driver = get_chrome()324 gg = webpac_jsp_crawler(325 driver,326 '嘉南藥理大學',327 "https://webpac.cnu.edu.tw/webpacIndex.jsp",328 ISBN329 )330 driver.close()331 worksheet.append_rows(gg.values.tolist())332 return gg333# 臺北市立圖書館 TPML V334def TPML(ISBN):335 sheet = ggSheet()336 worksheet = sheet.get_worksheet(0)337 driver = get_chrome()338 gg = webpac_jsp_crawler(339 driver,340 '臺北市立圖書館',341 'https://book.tpml.edu.tw/webpac/webpacIndex.jsp',342 ISBN343 )344 driver.close()345 worksheet.append_rows(gg.values.tolist())346 return gg347# 國立臺灣藝術大學 NTUA V348def NTUA(ISBN):349 sheet = ggSheet()350 worksheet = sheet.get_worksheet(0)351 driver = get_chrome()352 gg = webpac_jsp_crawler(353 driver,354 '國立臺灣藝術大學',355 'http://webpac.ntua.edu.tw/webpacIndex.jsp',356 ISBN357 )358 driver.close()359 worksheet.append_rows(gg.values.tolist())360 return gg361# 臺北市立大學 UTaipei V362def UTaipei(ISBN):363 sheet = ggSheet()364 worksheet = sheet.get_worksheet(0)365 driver = get_chrome()366 gg = webpac_jsp_crawler(367 driver,368 '臺北市立大學',369 'http://lib.utaipei.edu.tw/webpac/webpacIndex.jsp',370 ISBN371 )372 driver.close()373 worksheet.append_rows(gg.values.tolist())374 return gg375# 國立臺北科技大學 NTUT V376def NTUT(ISBN):377 sheet = ggSheet()378 worksheet = sheet.get_worksheet(0)379 driver = get_chrome()380 gg = webpac_jsp_crawler(381 driver,382 '國立臺北科技大學',383 'https://libholding.ntut.edu.tw/webpacIndex.jsp',384 ISBN385 )386 driver.close()387 worksheet.append_rows(gg.values.tolist())388 return gg389# 臺北醫學大學 TMU V390def TMU(ISBN):391 sheet = ggSheet()392 worksheet = sheet.get_worksheet(0)393 driver = get_chrome()394 gg = webpac_jsp_crawler(395 driver,396 '臺北醫學大學',397 'https://libelis.tmu.edu.tw/webpacIndex.jsp',398 ISBN399 )400 driver.close()401 worksheet.append_rows(gg.values.tolist())402 return gg403# 國立臺北商業大學 NTUB V404def NTUB(ISBN):405 sheet = ggSheet()406 worksheet = sheet.get_worksheet(0)407 driver = get_chrome()408 gg = webpac_jsp_crawler(409 driver,410 '國立臺北商業大學',411 'http://webpac.ntub.edu.tw/webpacIndex.jsp',412 ISBN413 )414 driver.close()415 worksheet.append_rows(gg.values.tolist())416 return gg417# 景文科技大學 JUST V418def JUST(ISBN):419 sheet = ggSheet()420 worksheet = sheet.get_worksheet(0)421 driver = get_chrome()422 gg = webpac_jsp_crawler(423 driver,424 '景文科技大學',425 'https://jinwenlib.just.edu.tw/webpacIndex.jsp',426 ISBN427 )428 driver.close()429 worksheet.append_rows(gg.values.tolist())430 return gg431# 致理科技大學 CLUT V432def CLUT(ISBN):433 sheet = ggSheet()434 worksheet = sheet.get_worksheet(0)435 driver = get_chrome()436 gg = webpac_jsp_crawler(437 driver,438 '致理科技大學',439 'http://hylib.chihlee.edu.tw/webpacIndex.jsp',440 ISBN441 )442 driver.close()443 worksheet.append_rows(gg.values.tolist())444 return gg445# 萬能科技大學 VNU V446def VNU(ISBN):447 sheet = ggSheet()448 worksheet = sheet.get_worksheet(0)449 driver = get_chrome()450 gg = webpac_jsp_crawler(451 driver,452 '萬能科技大學',453 'http://webpac.lib.vnu.edu.tw/webpacIndex.jsp',454 ISBN455 )456 driver.close()457 worksheet.append_rows(gg.values.tolist())458 return gg459# 健行科技大學 UCH V460def UCH(ISBN):461 sheet = ggSheet()462 worksheet = sheet.get_worksheet(0)463 driver = get_chrome()464 gg = webpac_jsp_crawler(465 driver,466 '健行科技大學',467 'https://library.uch.edu.tw/webpacIndex.jsp',468 ISBN469 )470 driver.close()471 worksheet.append_rows(gg.values.tolist())472 return gg473# 明新科技大學 MUST V474def MUST(ISBN):475 sheet = ggSheet()476 worksheet = sheet.get_worksheet(0)477 driver = get_chrome()478 gg = webpac_jsp_crawler(479 driver,480 '明新科技大學',481 'https://hylib.lib.must.edu.tw/webpacIndex.jsp',482 ISBN483 )484 driver.close()485 worksheet.append_rows(gg.values.tolist())486 return gg487# 國立空中大學 NOU V488def NOU(ISBN):489 sheet = ggSheet()490 worksheet = sheet.get_worksheet(0)491 driver = get_chrome()492 gg = webpac_jsp_crawler(493 driver,494 '國立空中大學',495 'https://hyweblib.nou.edu.tw/webpac/webpacIndex.jsp',496 ISBN497 )498 driver.close()499 worksheet.append_rows(gg.values.tolist())500 return gg501# 新竹市立圖書館 HCLIB V502def HCLIB(ISBN):503 sheet = ggSheet()504 worksheet = sheet.get_worksheet(0)505 driver = get_chrome()506 gg = webpac_jsp_crawler(507 driver,508 '新竹市立圖書館',509 'https://webpac.hcml.gov.tw/webpacIndex.jsp',510 ISBN511 )512 driver.close()513 worksheet.append_rows(gg.values.tolist())514 return gg515# 新竹縣公共圖書館 HCPL V516def HCPL(ISBN):517 sheet = ggSheet()518 worksheet = sheet.get_worksheet(0)519 driver = get_chrome()520 gg = webpac_jsp_crawler(521 driver,522 '新竹縣公共圖書館',523 'https://book.hchcc.gov.tw/webpacIndex.jsp',524 ISBN525 )526 driver.close()527 worksheet.append_rows(gg.values.tolist())528 return gg529# 苗栗縣立圖書館 Miaoli V530def Miaoli(ISBN):531 sheet = ggSheet()532 worksheet = sheet.get_worksheet(0)533 driver = get_chrome()534 gg = webpac_jsp_crawler(535 driver,536 '苗栗縣立圖書館',537 'https://webpac.miaoli.gov.tw/webpacIndex.jsp',538 ISBN539 )540 driver.close()541 worksheet.append_rows(gg.values.tolist())542 return gg543# 育達科技大學 YDU V544def YDU(ISBN):545 sheet = ggSheet()546 worksheet = sheet.get_worksheet(0)547 driver = get_chrome()548 gg = webpac_jsp_crawler(549 driver,550 '育達科技大學',551 'http://120.106.11.155/webpacIndex.jsp',552 ISBN553 )554 driver.close()555 worksheet.append_rows(gg.values.tolist())556 return gg557# 仁德醫護管理專科學校 Jente V558def Jente(ISBN):559 sheet = ggSheet()560 worksheet = sheet.get_worksheet(0)561 driver = get_chrome()562 gg = webpac_jsp_crawler(563 driver,564 '仁德醫護管理專科學校',565 'http://libopac.jente.edu.tw/webpacIndex.jsp',566 ISBN567 )568 driver.close()569 worksheet.append_rows(gg.values.tolist())570 return gg571# 中國科技大學 CUTE V572def CUTE(ISBN):573 sheet = ggSheet()574 worksheet = sheet.get_worksheet(0)575 driver = get_chrome()576 gg = webpac_jsp_crawler(577 driver,578 '中國科技大學',579 'https://webpac.cute.edu.tw/webpacIndex.jsp',580 ISBN581 )582 driver.close()583 worksheet.append_rows(gg.values.tolist())584 return gg585# 國立臺中教育大學 NTCU V586def NTCU(ISBN):587 sheet = ggSheet()588 worksheet = sheet.get_worksheet(0)589 driver = get_chrome()590 gg = webpac_jsp_crawler(591 driver,592 '國立臺中教育大學',593 'http://webpac.lib.ntcu.edu.tw/webpacIndex.jsp',594 ISBN595 )596 driver.close()597 worksheet.append_rows(gg.values.tolist())598 return gg599# 國立臺灣體育運動大學 NTUS V600def NTUS(ISBN):601 sheet = ggSheet()602 worksheet = sheet.get_worksheet(0)603 driver = get_chrome()604 gg = webpac_jsp_crawler(605 driver,606 '國立臺灣體育運動大學',607 'https://hylib.ntus.edu.tw/webpacIndex.jsp',608 ISBN609 )610 driver.close()611 worksheet.append_rows(gg.values.tolist())612 return gg613# 東海大學 THU V614def THU(ISBN):615 sheet = ggSheet()616 worksheet = sheet.get_worksheet(0)617 driver = get_chrome()618 gg = webpac_jsp_crawler(619 driver,620 '東海大學',621 'https://webpac.lib.thu.edu.tw/webpacIndex.jsp',622 ISBN623 )624 driver.close()625 worksheet.append_rows(gg.values.tolist())626 return gg627# 靜宜大學 PU V628def PU(ISBN):629 sheet = ggSheet()630 worksheet = sheet.get_worksheet(0)631 driver = get_chrome()632 gg = webpac_jsp_crawler(633 driver,634 '靜宜大學',635 'http://webpac.lib.pu.edu.tw/webpac/webpacIndex.jsp',636 ISBN637 )638 driver.close()639 worksheet.append_rows(gg.values.tolist())640 return gg641# 僑光科技大學 OCU V642def OCU(ISBN):643 sheet = ggSheet()644 worksheet = sheet.get_worksheet(0)645 driver = get_chrome()646 gg = webpac_jsp_crawler(647 driver,648 '僑光科技大學',649 'http://lib.webpac.ocu.edu.tw/webpacIndex.jsp',650 ISBN651 )652 driver.close()653 worksheet.append_rows(gg.values.tolist())654 return gg655# 國立彰化師範大學 NCUE V656def NCUE(ISBN):657 sheet = ggSheet()658 worksheet = sheet.get_worksheet(0)659 driver = get_chrome()660 gg = webpac_jsp_crawler(661 driver,662 '國立彰化師範大學',663 'https://book.ncue.edu.tw/webpacIndex.jsp',664 ISBN665 )666 driver.close()667 worksheet.append_rows(gg.values.tolist())668 return gg669# 雲林縣公共圖書館 YLCCB V670def YLCCB(ISBN):671 sheet = ggSheet()672 worksheet = sheet.get_worksheet(0)673 driver = get_chrome()674 gg = webpac_jsp_crawler(675 driver,676 '雲林縣公共圖書館',677 'http://library.ylccb.gov.tw/webpacIndex.jsp',678 ISBN679 )680 driver.close()681 worksheet.append_rows(gg.values.tolist())682 return gg683# 嘉義市立圖書館 CYLIB X(進不去...)684def CYLIB(ISBN):685 sheet = ggSheet()686 worksheet = sheet.get_worksheet(0)687 driver = get_chrome()688 gg = webpac_jsp_crawler(689 driver,690 '嘉義市立圖書館',691 'http://library.cabcy.gov.tw/webpacIndex.jsp',692 ISBN693 )694 driver.close()695 worksheet.append_rows(gg.values.tolist())696 return gg697# 嘉義縣圖書館 CYCPL V698def CYCPL(ISBN):699 sheet = ggSheet()700 worksheet = sheet.get_worksheet(0)701 driver = get_chrome()702 gg = webpac_jsp_crawler(703 driver,704 '嘉義縣圖書館',705 'https://www.cycab.gov.tw/webpacIndex.jsp',706 ISBN707 )708 driver.close()709 worksheet.append_rows(gg.values.tolist())710 return gg711# 南華大學 NHU V712def NHU(ISBN):713 sheet = ggSheet()714 worksheet = sheet.get_worksheet(0)715 driver = get_chrome()716 gg = webpac_jsp_crawler(717 driver,718 '南華大學',719 'http://hylib.nhu.edu.tw//webpacIndex.jsp',720 ISBN721 )722 driver.close()723 worksheet.append_rows(gg.values.tolist())724 return gg725# 遠東科技大學 FEU V726def FEU(ISBN):727 sheet = ggSheet()728 worksheet = sheet.get_worksheet(0)729 driver = get_chrome()730 gg = webpac_jsp_crawler(731 driver,732 '遠東科技大學',733 'http://hy.lib.feu.edu.tw/webpacIndex.jsp',734 ISBN735 )736 driver.close()737 worksheet.append_rows(gg.values.tolist())738 return gg739# 正修科技大學 CSU V740def CSU(ISBN):741 sheet = ggSheet()742 worksheet = sheet.get_worksheet(0)743 driver = get_chrome()744 gg = webpac_jsp_crawler(745 driver,746 '正修科技大學',747 'https://webpac2.csu.edu.tw/webpacIndex.jsp',748 ISBN749 )750 driver.close()751 worksheet.append_rows(gg.values.tolist())752 return gg753# 美和科技大學 Meiho V754def Meiho(ISBN):755 sheet = ggSheet()756 worksheet = sheet.get_worksheet(0)757 driver = get_chrome()758 gg = webpac_jsp_crawler(759 driver,760 '美和科技大學',761 'http://webpac.meiho.edu.tw/webpacIndex.jsp',762 ISBN763 )764 driver.close()765 worksheet.append_rows(gg.values.tolist())766 return gg767# 國立臺東大學 NTTU V768def NTTU(ISBN):769 sheet = ggSheet()770 worksheet = sheet.get_worksheet(0)771 driver = get_chrome()772 gg = webpac_jsp_crawler(773 driver,774 '國立臺東大學',775 'http://hylib.lib.nttu.edu.tw/webpac/webpacIndex.jsp',776 ISBN777 )778 driver.close()779 worksheet.append_rows(gg.values.tolist())780 return gg781# 臺東縣立圖書館 TTCPL V782def TTCPL(ISBN):783 sheet = ggSheet()784 worksheet = sheet.get_worksheet(0)785 driver = get_chrome()786 gg = webpac_jsp_crawler(787 driver,788 '臺東縣立圖書館',789 'http://library.ccl.ttct.edu.tw/webpacIndex.jsp',790 ISBN791 )792 driver.close()793 worksheet.append_rows(gg.values.tolist())794 return gg795# 國立金門大學 NQU V796def NQU(ISBN):797 sheet = ggSheet()798 worksheet = sheet.get_worksheet(0)799 driver = get_chrome()800 gg = webpac_jsp_crawler(801 driver,802 '國立金門大學',803 'https://lib.nqu.edu.tw/webpacIndex.jsp',804 ISBN805 )806 driver.close()807 worksheet.append_rows(gg.values.tolist())808 return gg809# 金門縣立圖書館 KMCPL V810def KMCPL(ISBN):811 sheet = ggSheet()812 worksheet = sheet.get_worksheet(0)813 driver = get_chrome()814 gg = webpac_jsp_crawler(815 driver,816 '金門縣立圖書館',817 'http://library.kmccc.edu.tw/webpacIndex.jsp',818 ISBN819 )820 driver.close()821 worksheet.append_rows(gg.values.tolist())822 return gg823# ------------------------------------最簡單的那種------------------------------------------824# easy_crawler()825# 海大|台科大|台師大|中原|逢甲|朝陽|中山|高師|文藻|大仁|中央826# 國立臺灣海洋大學 NTOU V827def NTOU(ISBN):828 try:829 scope = ['https://www.googleapis.com/auth/spreadsheets']830 creds = Credentials.from_service_account_file(831 "json_files_for_robot/books-319701-17701ae5510b.json", scopes=scope)832 gs = gspread.authorize(creds)833 sheet = gs.open_by_url(834 'https://docs.google.com/spreadsheets/d/17fJuHSGHnjHbyKJzTgzKpp1pe2J6sirK5QVjg2-8fFo/edit#gid=0')835 worksheet = sheet.get_worksheet(0)836 driver = webdriver.Chrome(837 options=my_options, desired_capabilities=my_capabilities)838 gg = easy_crawler(839 driver,840 '國立臺灣海洋大學',841 'https://ocean.ntou.edu.tw/search*cht/i?SEARCH=',842 ISBN843 )844 driver.close()845 worksheet.append_rows(gg.values.tolist())846 except Exception as e:847 print(f'在 NTOU(),發生錯誤:「{e}」')848 return849 else:850 return gg851# 國立臺灣科技大學 NTUST V852def NTUST(ISBN):853 sheet = ggSheet()854 worksheet = sheet.get_worksheet(0)855 driver = get_chrome()856 gg = easy_crawler(857 driver,858 '國立臺灣科技大學',859 "https://sierra.lib.ntust.edu.tw/search*cht/i?SEARCH=",860 ISBN861 )862 driver.close()863 worksheet.append_rows(gg.values.tolist())864 return gg865# 國立臺灣師範大學 NTNU V866def NTNU(ISBN):867 sheet = ggSheet()868 worksheet = sheet.get_worksheet(0)869 driver = get_chrome()870 gg = easy_crawler(871 driver,872 '國立臺灣師範大學',873 "https://opac.lib.ntnu.edu.tw/search*cht/i?SEARCH=",874 ISBN875 )876 driver.close()877 worksheet.append_rows(gg.values.tolist())878 return gg879# 中原大學 CYCU V880def CYCU(ISBN):881 sheet = ggSheet()882 worksheet = sheet.get_worksheet(0)883 driver = get_chrome()884 gg = easy_crawler(885 driver,886 '中原大學',887 "http://cylis.lib.cycu.edu.tw/search*cht/i",888 ISBN889 )890 driver.close()891 worksheet.append_rows(gg.values.tolist())892 return gg893# 逢甲大學 FCU V894def FCU(ISBN):895 sheet = ggSheet()896 worksheet = sheet.get_worksheet(0)897 driver = get_chrome()898 gg = easy_crawler(899 driver,900 '逢甲大學',901 "https://innopac.lib.fcu.edu.tw/search*cht/i",902 ISBN903 )904 driver.close()905 worksheet.append_rows(gg.values.tolist())906 return gg907# 朝陽科技大學 CYUT V908def CYUT(ISBN):909 sheet = ggSheet()910 worksheet = sheet.get_worksheet(0)911 driver = get_chrome()912 gg = easy_crawler(913 driver,914 '朝陽科技大學',915 "https://millennium.lib.cyut.edu.tw/search*cht/i",916 ISBN917 )918 driver.close()919 worksheet.append_rows(gg.values.tolist())920 return gg921# 國立中山大學 NSYSU V922def NSYSU(ISBN):923 sheet = ggSheet()924 worksheet = sheet.get_worksheet(0)925 driver = get_chrome()926 gg = easy_crawler(927 driver,928 '國立中山大學',929 "https://dec.lib.nsysu.edu.tw/search*cht/i",930 ISBN931 )932 driver.close()933 worksheet.append_rows(gg.values.tolist())934 return gg935# 國立高雄師範大學 NKNU V936def NKNU(ISBN):937 sheet = ggSheet()938 worksheet = sheet.get_worksheet(0)939 driver = get_chrome()940 gg = easy_crawler(941 driver,942 '國立高雄師範大學',943 "https://nknulib.nknu.edu.tw/search*cht/i",944 ISBN945 )946 driver.close()947 worksheet.append_rows(gg.values.tolist())948 return gg949# 文藻外語大學 WZU V950def WZU(ISBN):951 sheet = ggSheet()952 worksheet = sheet.get_worksheet(0)953 driver = get_chrome()954 gg = easy_crawler(955 driver,956 '文藻外語大學',957 "https://libpac.wzu.edu.tw/search*cht/i",958 ISBN959 )960 driver.close()961 worksheet.append_rows(gg.values.tolist())962 return gg963# 大仁科技大學 Tajen V964def Tajen(ISBN):965 sheet = ggSheet()966 worksheet = sheet.get_worksheet(0)967 driver = get_chrome()968 gg = easy_crawler(969 driver,970 '大仁科技大學',971 "http://lib.tajen.edu.tw/search*cht/i",972 ISBN973 )974 driver.close()975 worksheet.append_rows(gg.values.tolist())976 return gg977# 國立中央大學 NCU V978def NCU(ISBN):979 sheet = ggSheet()980 worksheet = sheet.get_worksheet(0)981 driver = get_chrome()982 gg = easy_crawler(983 driver,984 '國立中央大學',985 "https://opac.lib.ncu.edu.tw/search*cht/i",986 ISBN987 )988 driver.close()989 worksheet.append_rows(gg.values.tolist())990 return gg991# -------------------------------------改版?------------------------------------------992# webpac_pro_crawler()993# 中研院|文化|輔仁|陽交大994# 中央研究院 SINICA V995def SINICA(ISBN):996 sheet = ggSheet()997 worksheet = sheet.get_worksheet(0)998 driver = get_chrome()999 gg = webpac_pro_crawler(1000 driver,1001 '中央研究院',1002 "https://las.sinica.edu.tw/*cht",1003 ISBN1004 )1005 driver.close()1006 worksheet.append_rows(gg.values.tolist())1007 return gg1008# 中國文化大學 PCCU V1009def PCCU(ISBN):1010 sheet = ggSheet()1011 worksheet = sheet.get_worksheet(0)1012 driver = get_chrome()1013 gg = webpac_pro_crawler(1014 driver,1015 '中國文化大學',1016 "https://webpac.pccu.edu.tw/*cht",1017 ISBN1018 )1019 driver.close()1020 worksheet.append_rows(gg.values.tolist())1021 return gg1022# 輔仁大學 FJU V1023def FJU(ISBN):1024 sheet = ggSheet()1025 worksheet = sheet.get_worksheet(0)1026 driver = get_chrome()1027 gg = webpac_pro_crawler(1028 driver,1029 '輔仁大學',1030 "https://library.lib.fju.edu.tw/",1031 ISBN1032 )1033 driver.close()1034 worksheet.append_rows(gg.values.tolist())1035 return gg1036# 國立陽明交通大學 NYCU V1037def NYCU(ISBN):1038 sheet = ggSheet()1039 worksheet = sheet.get_worksheet(0)1040 driver = get_chrome()1041 gg = webpac_pro_crawler(1042 driver,1043 '國立陽明交通大學',1044 "https://library.ym.edu.tw/screens/opacmenu_cht_s7.html",1045 ISBN1046 )1047 driver.close()1048 worksheet.append_rows(gg.values.tolist())1049 return gg1050# 國立成功大學 NYCU V1051def NCKU(ISBN):1052 sheet = ggSheet()1053 worksheet = sheet.get_worksheet(0)1054 driver = get_chrome()1055 gg = webpac_pro_crawler(1056 driver,1057 '國立成功大學',1058 "https://weblis.lib.ncku.edu.tw/",1059 ISBN1060 )1061 driver.close()1062 worksheet.append_rows(gg.values.tolist())1063 return gg1064# -----------------------------------ajax_page------------------------------------------------1065# webpac_ajax_crawler()1066# 新北市|高空大|屏大1067# 新北市立圖書館 NTPC V1068def NTPC(ISBN):1069 sheet = ggSheet()1070 worksheet = sheet.get_worksheet(0)1071 driver = get_chrome()1072 gg = webpac_ajax_crawler(1073 driver,1074 '新北市立圖書館',1075 "https://webpac.tphcc.gov.tw/webpac/search.cfm",1076 ISBN1077 )1078 driver.close()1079 worksheet.append_rows(gg.values.tolist())1080 return gg1081# 高雄市立空中大學 OUK V1082def OUK(ISBN):1083 sheet = ggSheet()1084 worksheet = sheet.get_worksheet(0)1085 driver = get_chrome()1086 gg = webpac_ajax_crawler(1087 driver,1088 '高雄市立空中大學',1089 "https://webpac.ouk.edu.tw/webpac/search.cfm",1090 ISBN1091 )1092 driver.close()1093 worksheet.append_rows(gg.values.tolist())1094 return gg1095# 國立屏東大學 NPTU V1096def NPTU(ISBN):1097 sheet = ggSheet()1098 worksheet = sheet.get_worksheet(0)1099 driver = get_chrome()1100 gg = webpac_ajax_crawler(1101 driver,1102 '國立屏東大學',1103 "https://webpac.nptu.edu.tw/webpac/search.cfm",1104 ISBN1105 )1106 driver.close()1107 worksheet.append_rows(gg.values.tolist())1108 return gg1109# -----------------------------------一直切iframe------------------------------------------------1110# webpac_aspx_crawler()1111# 樹德|首府|崑山|弘光|修平|華夏|真理|實踐|華梵|聯合1112# 樹德科技大學 STU V1113def STU(ISBN):1114 sheet = ggSheet()1115 worksheet = sheet.get_worksheet(0)1116 driver = get_chrome()1117 gg = webpac_aspx_crawler(1118 driver,1119 '樹德科技大學',1120 "https://webpac.stu.edu.tw/webopac/",1121 ISBN1122 )1123 driver.close()1124 worksheet.append_rows(gg.values.tolist())1125 return gg1126# 台灣首府大學 TSU V1127def TSU(ISBN):1128 sheet = ggSheet()1129 worksheet = sheet.get_worksheet(0)1130 driver = get_chrome()1131 gg = webpac_aspx_crawler(1132 driver,1133 '台灣首府大學',1134 "http://120.114.1.19/webopac/Jycx.aspx?dc=1&fc=1&n=7",1135 ISBN1136 )1137 driver.close()1138 worksheet.append_rows(gg.values.tolist())1139 return gg1140# 崑山科技大學 KSU V1141def KSU(ISBN):1142 sheet = ggSheet()1143 worksheet = sheet.get_worksheet(0)1144 driver = get_chrome()1145 gg = webpac_aspx_crawler(1146 driver,1147 '崑山科技大學',1148 "https://weblis.lib.ksu.edu.tw/webopac/",1149 ISBN1150 )1151 driver.close()1152 worksheet.append_rows(gg.values.tolist())1153 return gg1154# 弘光科技大學 HKU V1155def HKU(ISBN):1156 sheet = ggSheet()1157 worksheet = sheet.get_worksheet(0)1158 driver = get_chrome()1159 gg = webpac_aspx_crawler(1160 driver,1161 '弘光科技大學',1162 "https://webpac.hk.edu.tw/webopac/",1163 ISBN1164 )1165 driver.close()1166 worksheet.append_rows(gg.values.tolist())1167 return gg1168# 修平科技大學 HUST V1169def HUST(ISBN):1170 sheet = ggSheet()1171 worksheet = sheet.get_worksheet(0)1172 driver = get_chrome()1173 gg = webpac_aspx_crawler(1174 driver,1175 '修平科技大學',1176 "http://163.17.79.108/webopac/",1177 ISBN1178 )1179 driver.close()1180 worksheet.append_rows(gg.values.tolist())1181 return gg1182# 華夏科技大學 HWH V1183def HWH(ISBN):1184 sheet = ggSheet()1185 worksheet = sheet.get_worksheet(0)1186 driver = get_chrome()1187 gg = webpac_aspx_crawler(1188 driver,1189 '華夏科技大學',1190 "http://webopac.lib.hwh.edu.tw/webopac/",1191 ISBN1192 )1193 driver.close()1194 worksheet.append_rows(gg.values.tolist())1195 return gg1196# 真理大學 AU V1197def AU(ISBN):1198 try:1199 print('(./INSTs.py)執行這行1')1200 scope = ['https://www.googleapis.com/auth/spreadsheets']1201 print('(./INSTs.py)執行這行2')1202 creds = Credentials.from_service_account_file(1203 "json_files_for_robot/books-319701-17701ae5510b.json", scopes=scope)1204 print('(./INSTs.py)執行這行3')1205 gs = gspread.authorize(creds)1206 print('(./INSTs.py)執行這行4')1207 sheet = gs.open_by_url(1208 'https://docs.google.com/spreadsheets/d/17fJuHSGHnjHbyKJzTgzKpp1pe2J6sirK5QVjg2-8fFo/edit#gid=0')1209 print('(./INSTs.py)執行這行5')1210 worksheet = sheet.get_worksheet(0)1211 print('(./INSTs.py)執行這行6')1212 print('(./INSTs.py)執行這行7')1213 driver = webdriver.Chrome(1214 options=my_options, desired_capabilities=my_capabilities)1215 print('(./INSTs.py)執行這行8')1216 print('(./INSTs.py)執行這行9')1217 gg = webpac_aspx_crawler(1218 driver,1219 '真理大學',1220 "https://lib.au.edu.tw/webopac/",1221 ISBN1222 )1223 driver.close()1224 worksheet.append_rows(gg.values.tolist())1225 except Exception as e:1226 print(f'函式 AU() 發生錯誤:{e}')1227 return1228 else:1229 return gg1230# 實踐大學 USC V1231def USC(ISBN):1232 sheet = ggSheet()1233 worksheet = sheet.get_worksheet(0)1234 driver = get_chrome()1235 gg = webpac_aspx_crawler(1236 driver,1237 '實踐大學',1238 "https://webopac.usc.edu.tw/webopac/",1239 ISBN1240 )1241 driver.close()1242 worksheet.append_rows(gg.values.tolist())1243 return gg1244# 華梵大學 HFU V1245def HFU(ISBN):1246 sheet = ggSheet()1247 worksheet = sheet.get_worksheet(0)1248 driver = get_chrome()1249 gg = webpac_aspx_crawler(1250 driver,1251 '華梵大學',1252 "http://210.59.113.12/webopac/",1253 ISBN1254 )1255 driver.close()1256 worksheet.append_rows(gg.values.tolist())1257 return gg1258# 國立聯合大學 NUU V1259def NUU(ISBN):1260 sheet = ggSheet()1261 worksheet = sheet.get_worksheet(0)1262 driver = get_chrome()1263 gg = webpac_aspx_crawler(1264 driver,1265 '國立聯合大學',1266 "http://210.60.171.7/webopac/",1267 ISBN1268 )1269 driver.close()1270 worksheet.append_rows(gg.values.tolist())1271 return gg1272# -----------------------------------按館藏地展開table------------------------------------------------1273# uhtbin_crawler()1274# 國北護|大同|國體大1275# 國立臺北護理健康大學 NTUNHS V1276def NTUNHS(ISBN):1277 sheet = ggSheet()1278 worksheet = sheet.get_worksheet(0)1279 driver = get_chrome()1280 gg = uhtbin_crawler(1281 driver,1282 '國立臺北護理健康大學',1283 "http://140.131.94.8/uhtbin/webcat",1284 ISBN1285 )1286 driver.close()1287 worksheet.append_rows(gg.values.tolist())1288 return gg1289# 大同大學 TTU V1290def TTU(ISBN):1291 sheet = ggSheet()1292 worksheet = sheet.get_worksheet(0)1293 driver = get_chrome()1294 gg = uhtbin_crawler(1295 driver,1296 '大同大學',1297 "http://140.129.23.14/uhtbin/webcat",1298 ISBN1299 )1300 driver.close()1301 worksheet.append_rows(gg.values.tolist())1302 return gg1303# 國立體育大學 NTSU V1304def NTSU(ISBN):1305 sheet = ggSheet()1306 worksheet = sheet.get_worksheet(0)1307 driver = get_chrome()1308 gg = uhtbin_crawler(1309 driver,1310 '國立體育大學',1311 "http://192.83.181.243/uhtbin/webcat",1312 ISBN1313 )1314 driver.close()1315 worksheet.append_rows(gg.values.tolist())1316 return gg1317# --------------------------------------醜得清新脫俗------------------------------------------------1318# ugly_crawler()1319# 連江縣|開南1320def ugly_crawler(driver, org, org_url, ISBN):1321 try:1322 table = []1323 driver.get(org_url)1324 search_ISBN(driver, ISBN, 'ISBN')1325 if wait_for_element_present(driver, '重新查詢', by=By.LINK_TEXT):1326 print(f'在「{org}」找不到「{ISBN}」')1327 return1328 tgt = accurately_find_table_and_read_it(driver, 'table', -2)1329 tgt['圖書館'], tgt['連結'] = org, driver.current_url1330 table.append(tgt)1331 table = organize_columns(table)1332 except Exception as e:1333 print(f'在「{org}」搜尋「{ISBN}」時,發生錯誤,錯誤訊息為:「{e}」!')1334 return1335 else:1336 return table1337# 連江縣公共圖書館 Matsu V1338def Matsu(ISBN):1339 sheet = ggSheet()1340 worksheet = sheet.get_worksheet(0)1341 driver = get_chrome()1342 gg = ugly_crawler(1343 driver,1344 '連江縣公共圖書館',1345 "http://210.63.206.76/Webpac2/msearch.dll/",1346 ISBN1347 )1348 driver.close()1349 worksheet.append_rows(gg.values.tolist())1350 return gg1351# 開南大學 KNU V1352def KNU(ISBN):1353 sheet = ggSheet()1354 worksheet = sheet.get_worksheet(0)1355 driver = get_chrome()1356 gg = ugly_crawler(1357 driver,1358 '開南大學',1359 "http://www.lib.knu.edu.tw/Webpac2/msearch.dll/",1360 ISBN1361 )1362 driver.close()1363 worksheet.append_rows(gg.values.tolist())1364 return gg1365# ---------------------------------------藍藍放大鏡------------------------------------------------1366# toread_crawler()1367# 東專|醒吾|彰化縣|高醫|虎科|聖約翰|東南|新生|崇仁|元培1368# ------------國立臺東專科學校-------------1369def NTC(ISBN):1370 sheet = ggSheet()1371 worksheet = sheet.get_worksheet(0)1372 driver = get_chrome()1373 gg = toread_crawler(1374 driver,1375 '國立臺東專科學校',1376 'https://library.ntc.edu.tw/toread/opac',1377 ISBN1378 )1379 driver.close()1380 worksheet.append_rows(gg.values.tolist())1381 return gg1382# ------------醒吾科技大學-------------1383def HWU(ISBN):1384 sheet = ggSheet()1385 worksheet = sheet.get_worksheet(0)1386 driver = get_chrome()1387 gg = toread_crawler(1388 driver,1389 org='醒吾科技大學',1390 org_url="http://120.102.129.237/toread/opac",1391 ISBN=ISBN1392 )1393 driver.close()1394 worksheet.append_rows(gg.values.tolist())1395 return gg1396# 彰化縣公共圖書館 CHPL V1397def CHPL(ISBN):1398 sheet = ggSheet()1399 worksheet = sheet.get_worksheet(0)1400 driver = get_chrome()1401 gg = toread_crawler(1402 driver,1403 '彰化縣公共圖書館',1404 "https://library.toread.bocach.gov.tw/toread/opac",1405 ISBN1406 )1407 driver.close()1408 worksheet.append_rows(gg.values.tolist())1409 return gg1410# 高雄醫學大學 KMU V1411def KMU(ISBN):1412 sheet = ggSheet()1413 worksheet = sheet.get_worksheet(0)1414 driver = get_chrome()1415 gg = toread_crawler(1416 driver,1417 '高雄醫學大學',1418 "https://toread.kmu.edu.tw/toread/opac",1419 ISBN1420 )1421 driver.close()1422 worksheet.append_rows(gg.values.tolist())1423 return gg1424# 國立虎尾科技大學 NFU V1425def NFU(ISBN):1426 sheet = ggSheet()1427 worksheet = sheet.get_worksheet(0)1428 driver = get_chrome()1429 gg = toread_crawler(1430 driver,1431 '國立虎尾科技大學',1432 "https://toread.lib.nfu.edu.tw/toread/opac",1433 ISBN1434 )1435 driver.close()1436 worksheet.append_rows(gg.values.tolist())1437 return gg1438# 聖約翰科技大學 SJU V1439def SJU(ISBN):1440 sheet = ggSheet()1441 worksheet = sheet.get_worksheet(0)1442 driver = get_chrome()1443 gg = toread_crawler(1444 driver,1445 '聖約翰科技大學',1446 "http://163.21.66.231:8080/toread/opac",1447 ISBN1448 )1449 driver.close()1450 worksheet.append_rows(gg.values.tolist())1451 return gg1452# 東南科技大學 TNU V1453def TNU(ISBN):1454 sheet = ggSheet()1455 worksheet = sheet.get_worksheet(0)1456 driver = get_chrome()1457 gg = toread_crawler(1458 driver,1459 '東南科技大學',1460 "http://140.129.140.176/toread/opac",1461 ISBN1462 )1463 driver.close()1464 worksheet.append_rows(gg.values.tolist())1465 return gg1466# 新生醫護管理專科學校 HSC V1467def HSC(ISBN):1468 sheet = ggSheet()1469 worksheet = sheet.get_worksheet(0)1470 driver = get_chrome()1471 gg = toread_crawler(1472 driver,1473 '新生醫護管理專科學校',1474 "http://163.25.34.60:8080/toread/opac",1475 ISBN1476 )1477 driver.close()1478 worksheet.append_rows(gg.values.tolist())1479 return gg1480# 崇仁醫護管理專科學校 CJC V1481def CJC(ISBN):1482 sheet = ggSheet()1483 worksheet = sheet.get_worksheet(0)1484 driver = get_chrome()1485 gg = toread_crawler(1486 driver,1487 '崇仁醫護管理專科學校',1488 "http://toread.cjc.edu.tw/toread/opac",1489 ISBN1490 )1491 driver.close()1492 worksheet.append_rows(gg.values.tolist())1493 return gg1494# 元培醫事科技大學 YPU V1495def YPU(ISBN):1496 sheet = ggSheet()1497 worksheet = sheet.get_worksheet(0)1498 driver = get_chrome()1499 gg = toread_crawler(1500 driver,1501 '元培醫事科技大學',1502 "http://120.106.195.31/toread/opac",1503 ISBN1504 )1505 driver.close()1506 worksheet.append_rows(gg.values.tolist())1507 return gg1508# 嶺東科技大學 LTU V1509def LTU(ISBN):1510 sheet = ggSheet()1511 worksheet = sheet.get_worksheet(0)1512 driver = get_chrome()1513 gg = toread_crawler(1514 driver,1515 '嶺東科技大學',1516 "http://192.192.100.39/toread/opac",1517 ISBN1518 )1519 driver.close()1520 worksheet.append_rows(gg.values.tolist())1521 return gg1522# 明道大學 MDU V1523def MDU(ISBN):1524 sheet = ggSheet()1525 worksheet = sheet.get_worksheet(0)1526 driver = get_chrome()1527 gg = toread_crawler(1528 driver,1529 '明道大學',1530 "http://210.60.94.144/toread/opac",1531 ISBN1532 )1533 driver.close()1534 worksheet.append_rows(gg.values.tolist())1535 return gg1536# 大葉大學 DYU V1537def DYU(ISBN):1538 sheet = ggSheet()1539 worksheet = sheet.get_worksheet(0)1540 driver = get_chrome()1541 gg = toread_crawler(1542 driver,1543 '大葉大學',1544 "http://webpac.dyu.edu.tw/toread311_DYU/opac/Search.page",1545 ISBN1546 )1547 driver.close()1548 worksheet.append_rows(gg.values.tolist())1549 return gg1550# 建國科技大學 CTU V1551def CTU(ISBN):1552 sheet = ggSheet()1553 worksheet = sheet.get_worksheet(0)1554 driver = get_chrome()1555 gg = toread_crawler(1556 driver,1557 '建國科技大學',1558 "https://webpac.lib.ctu.edu.tw/toread/opac",1559 ISBN1560 )1561 driver.close()1562 worksheet.append_rows(gg.values.tolist())1563 return gg1564# 南開科技大學 NKUT V1565def NKUT(ISBN):1566 sheet = ggSheet()1567 worksheet = sheet.get_worksheet(0)1568 driver = get_chrome()1569 gg = toread_crawler(1570 driver,1571 '南開科技大學',1572 "http://webpac.nkut.edu.tw/toread/opac",1573 ISBN1574 )1575 driver.close()1576 worksheet.append_rows(gg.values.tolist())1577 return gg1578# 國立高雄大學 NUK V1579def NUK(ISBN):1580 sheet = ggSheet()1581 worksheet = sheet.get_worksheet(0)1582 driver = get_chrome()1583 gg = toread_crawler(1584 driver,1585 '國立高雄大學',1586 "https://libopac.nuk.edu.tw/toread/opac",1587 ISBN1588 )1589 driver.close()1590 worksheet.append_rows(gg.values.tolist())1591 return gg1592# 國立東華大學 NDHU V1593def NDHU(ISBN):1594 sheet = ggSheet()1595 worksheet = sheet.get_worksheet(0)1596 driver = get_chrome()1597 gg = toread_crawler(1598 driver,1599 '國立東華大學',1600 "https://books-lib.ndhu.edu.tw/toread/opac",1601 ISBN1602 )1603 driver.close()1604 worksheet.append_rows(gg.values.tolist())1605 return gg1606# ---------------------------------------Webpac2.0------------------------------------------------1607# webpac_two_cralwer()1608# 北藝大|勤益|義守|中山醫|國衛院1609# 國立臺北藝術大學 TNUA V OK1610def TNUA(ISBN):1611 sheet = ggSheet()1612 worksheet = sheet.get_worksheet(0)1613 driver = get_chrome()1614 gg = webpac_two_cralwer(1615 driver,1616 '國立臺北藝術大學',1617 "http://203.64.5.158/webpac/",1618 ISBN1619 )1620 driver.close()1621 worksheet.append_rows(gg.values.tolist())1622 return gg1623# 國立勤益科技大學 NCUT V OK1624def NCUT(ISBN):1625 sheet = ggSheet()1626 worksheet = sheet.get_worksheet(0)1627 driver = get_chrome()1628 gg = webpac_two_cralwer(1629 driver,1630 '國立勤益科技大學',1631 "http://140.128.95.172/webpac/",1632 ISBN1633 )1634 driver.close()1635 worksheet.append_rows(gg.values.tolist())1636 return gg1637# 義守大學 ISU V1638def ISU(ISBN):1639 sheet = ggSheet()1640 worksheet = sheet.get_worksheet(0)1641 driver = get_chrome()1642 gg = webpac_two_cralwer(1643 driver,1644 '義守大學',1645 "http://webpac.isu.edu.tw/webpac/",1646 ISBN1647 )1648 driver.close()1649 worksheet.append_rows(gg.values.tolist())1650 return gg1651# 中山醫學大學 CSMU V1652def CSMU(ISBN):1653 sheet = ggSheet()1654 worksheet = sheet.get_worksheet(0)1655 driver = get_chrome()1656 gg = webpac_two_cralwer(1657 driver,1658 '中山醫學大學',1659 "http://140.128.138.208/webpac/",1660 ISBN1661 )1662 driver.close()1663 worksheet.append_rows(gg.values.tolist())1664 return gg1665# 國家衛生研究院 NHRI V1666def NHRI(ISBN):1667 sheet = ggSheet()1668 worksheet = sheet.get_worksheet(0)1669 driver = get_chrome()1670 gg = webpac_two_cralwer(1671 driver,1672 '國家衛生研究院',1673 "http://webpac.nhri.edu.tw/webpac/",1674 ISBN1675 )1676 driver.close()1677 worksheet.append_rows(gg.values.tolist())1678 return gg1679# ------------------------------------cfm------------------------------------------1680# webpac_cfm_crawler()1681# 北大|城市科大|德明|龍華|臺中市|中國醫|亞洲|臺南市|慈濟|澎科1682# 國立臺北大學 NTPU X(卡在進table前的頁面)1683def NTPU(ISBN):1684 sheet = ggSheet()1685 worksheet = sheet.get_worksheet(0)1686 driver = get_chrome()1687 gg = webpac_cfm_crawler(1688 driver,1689 '國立臺北大學',1690 "http://webpac.lib.ntpu.edu.tw/search.cfm",1691 ISBN1692 )1693 driver.close()1694 worksheet.append_rows(gg.values.tolist())1695 return gg1696# 臺北城市科技大學 TPCU V1697def TPCU(ISBN):1698 sheet = ggSheet()1699 worksheet = sheet.get_worksheet(0)1700 driver = get_chrome()1701 gg = webpac_cfm_crawler(1702 driver,1703 '臺北城市科技大學',1704 "http://120.102.52.73/webpac/search.cfm",1705 ISBN1706 )1707 driver.close()1708 worksheet.append_rows(gg.values.tolist())1709 return gg1710# 德明財經科技大學 TMUST V1711def TMUST(ISBN):1712 sheet = ggSheet()1713 worksheet = sheet.get_worksheet(0)1714 driver = get_chrome()1715 gg = webpac_cfm_crawler(1716 driver,1717 '德明財經科技大學',1718 "http://140.131.140.11/webpac/search.cfm",1719 ISBN1720 )1721 driver.close()1722 worksheet.append_rows(gg.values.tolist())1723 return gg1724# 龍華科技大學 LHU V1725def LHU(ISBN):1726 sheet = ggSheet()1727 worksheet = sheet.get_worksheet(0)1728 driver = get_chrome()1729 gg = webpac_cfm_crawler(1730 driver,1731 '龍華科技大學',1732 "https://webpac.lhu.edu.tw/webpac/search.cfm",1733 ISBN1734 )1735 driver.close()1736 worksheet.append_rows(gg.values.tolist())1737 return gg1738# 臺中市立圖書館 TCPL V1739def TCPL(ISBN):1740 sheet = ggSheet()1741 worksheet = sheet.get_worksheet(0)1742 driver = get_chrome()1743 gg = webpac_cfm_crawler(1744 driver,1745 '臺中市立圖書館',1746 "https://ipac.library.taichung.gov.tw/webpac/search.cfm",1747 ISBN1748 )1749 driver.close()1750 worksheet.append_rows(gg.values.tolist())1751 return gg1752# 中國醫藥大學 CMU V1753def CMU(ISBN):1754 sheet = ggSheet()1755 worksheet = sheet.get_worksheet(0)1756 driver = get_chrome()1757 gg = webpac_cfm_crawler(1758 driver,1759 '中國醫藥大學',1760 "http://weblis.cmu.edu.tw/webpac/search.cfm",1761 ISBN1762 )1763 driver.close()1764 worksheet.append_rows(gg.values.tolist())1765 return gg1766# 亞洲大學 Asia V1767def Asia(ISBN):1768 sheet = ggSheet()1769 worksheet = sheet.get_worksheet(0)1770 driver = get_chrome()1771 gg = webpac_cfm_crawler(1772 driver,1773 '亞洲大學',1774 "http://aulib.asia.edu.tw/webpac/search.cfm",1775 ISBN1776 )1777 driver.close()1778 worksheet.append_rows(gg.values.tolist())1779 return gg1780# 臺南市立圖書館 TNPL V1781def TNPL(ISBN):1782 sheet = ggSheet()1783 worksheet = sheet.get_worksheet(0)1784 driver = get_chrome()1785 gg = webpac_cfm_crawler(1786 driver,1787 '臺南市立圖書館',1788 "https://lib.tnml.tn.edu.tw/webpac/search.cfm",1789 ISBN1790 )1791 driver.close()1792 worksheet.append_rows(gg.values.tolist())1793 return gg1794# 慈濟大學 TCU V1795def TCU(ISBN):1796 sheet = ggSheet()1797 worksheet = sheet.get_worksheet(0)1798 driver = get_chrome()1799 gg = webpac_cfm_crawler(1800 driver,1801 '慈濟大學',1802 "http://www.webpac.tcu.edu.tw/webpac/search.cfm",1803 ISBN1804 )1805 driver.close()1806 worksheet.append_rows(gg.values.tolist())1807 return gg1808# 國立澎湖科技大學 NPU V OK1809def NPU(ISBN):1810 sheet = ggSheet()1811 worksheet = sheet.get_worksheet(0)1812 driver = get_chrome()1813 gg = webpac_cfm_crawler(1814 driver,1815 '國立澎湖科技大學',1816 "https://inspire.npu.edu.tw/webpac/search.cfm",1817 ISBN1818 )1819 driver.close()1820 worksheet.append_rows(gg.values.tolist())1821 return gg1822# ------------------------------被獨立出來的基隆---------------------------------------1823def 基隆市公共圖書館(driver, org, org_url, ISBN):1824 try:1825 # 進入"搜尋主頁"1826 driver.get(org_url)1827 # 等待點擊"進階查詢"按鈕,接著點擊1828 WebDriverWait(driver, 30).until(1829 EC.element_to_be_clickable((By.LINK_TEXT, '進階檢索'))).click()1830 time.sleep(2) # JavaScript 動畫,強制等待1831 # 等待定位"下拉式選單",選擇以 ISBN 方式搜尋1832 search_field = WebDriverWait(driver, 10).until(1833 EC.presence_of_element_located((By.ID, 'as_type_1')))1834 select = Select(search_field)1835 select.select_by_value('i')1836 # 定位"搜尋欄",輸入 ISBN1837 search_input = driver.find_element_by_id('as_keyword_1')1838 search_input.send_keys(ISBN)1839 search_input.send_keys(Keys.ENTER)1840 time.sleep(8) # 基隆的系統太詭異了,強制等待1841 soup = BeautifulSoup(driver.page_source, "html.parser")1842 results = len(soup.find_all("div", "list_box"))1843 if results < 2:1844 WebDriverWait(driver, 10).until(1845 EC.presence_of_element_located(1846 (By.CSS_SELECTOR, "table.list.list_border")))1847 time.sleep(2)1848 table = pd.read_html(driver.page_source)[0]1849 else:1850 table = []1851 for li in soup.find_all("div", "list_box"):1852 url_temp = "https://webpac.klccab.gov.tw/webpac/" + li.find(1853 "a", "btn")["href"]1854 driver.get(url_temp)1855 wait.until(1856 EC.presence_of_element_located(1857 (By.CSS_SELECTOR, "table.list.list_border")))1858 time.sleep(2)1859 table.append(1860 pd.read_html(driver.page_source, encoding="utf-8")[0])1861 table = pd.concat(table, axis=0, ignore_index=True)1862 table['圖書館'], table['連結'] = org, driver.current_url1863 table = organize_columns(table)1864 table = statuss(table)1865 return table1866 except:1867 print(f'《{ISBN}》在「{org_url}」無法爬取')1868# 基隆市公共圖書館 KLCCAB X(無館藏資料時會掛掉)1869def KLCCAB(ISBN):1870 sheet = ggSheet()1871 worksheet = sheet.get_worksheet(0)1872 driver = get_chrome()1873 gg = 基隆市公共圖書館(1874 driver,1875 '基隆市公共圖書館',1876 "https://webpac.klccab.gov.tw/webpac/search.cfm",1877 ISBN1878 )1879 driver.close()1880 worksheet.append_rows(gg.values.tolist())1881 return gg1882# ------------------------------------難形容的特殊------------------------------------------1883# sirsidynix_crawler()1884# 中科大|南投縣|南藝大1885# 國立臺中科技大學 NUTC1886def NUTC(ISBN):1887 sheet = ggSheet()1888 worksheet = sheet.get_worksheet(0)1889 driver = get_chrome()1890 gg = sirsidynix_crawler(1891 driver,1892 '國立臺中科技大學',1893 "https://ntit.ent.sirsidynix.net/client/zh_TW/NUTC",1894 ISBN1895 )1896 driver.close()1897 worksheet.append_rows(gg.values.tolist())1898 return gg1899# 南投縣圖書館 NTCPL1900def NTCPL(ISBN):1901 sheet = ggSheet()1902 worksheet = sheet.get_worksheet(0)1903 driver = get_chrome()1904 gg = sirsidynix_crawler(1905 driver,1906 '南投縣圖書館',1907 'https://nccc.ent.sirsi.net/client/zh_TW/main',1908 ISBN1909 )1910 driver.close()1911 worksheet.append_rows(gg.values.tolist())1912 return gg1913# 國立臺南藝術大學 TNNUA OK1914def TNNUA(ISBN):1915 sheet = ggSheet()1916 worksheet = sheet.get_worksheet(0)1917 driver = get_chrome()1918 gg = sirsidynix_crawler(1919 driver,1920 '國立臺南藝術大學',1921 'https://tnnua.ent.sirsi.net/client/zh_TW/tnnua/?',1922 ISBN1923 )1924 driver.close()1925 worksheet.append_rows(gg.values.tolist())1926 return gg1927# ------------------------------------文化局旗下------------------------------------------1928# moc_thm_crawler()1929# 臺史館|臺文館|史前館|1930# 國立臺灣史前文化博物館 NMP1931def NMP(ISBN):1932 sheet = ggSheet()1933 worksheet = sheet.get_worksheet(0)1934 driver = get_chrome()1935 gg = moc_thm_crawler(1936 driver,1937 '國立臺灣史前文化博物館',1938 "https://lib.moc.gov.tw/F?func=find-d-0&local_base=THM04",1939 ISBN1940 )1941 driver.close()1942 worksheet.append_rows(gg.values.tolist())1943 return gg1944# ---------------------------------被獨立出來的國圖----------------------------------------1945def 國家圖書館(driver, org, org_url, ISBN):1946 try:1947 driver.get(org_url)1948 select_ISBN_strategy(driver, 'find_code', 'ISBN')1949 search_ISBN(driver, ISBN, 'request')1950 # 點擊"書在哪裡(請點選)",進入"書目資料"1951 wait_for_element_clickable(driver, '書在哪裡(請點選)').click()1952 table = accurately_find_table_and_read_it(driver, 'table', -2)1953 if 0 in table.columns:1954 print(f'在「{org}」找不到「{ISBN}」')1955 return1956 table['圖書館'], table['連結'] = org, driver.current_url1957 table = organize_columns(table)1958 except Exception as e:1959 # 沒有物件可以 click,表示"零筆"搜尋結果1960 print(f'在「{org}」搜尋「{ISBN}」時,發生錯誤,錯誤訊息為:「{e}」!')1961 return1962 return table1963# 國家圖書館 NCL V1964def NCL(ISBN):1965 sheet = ggSheet()1966 worksheet = sheet.get_worksheet(0)1967 driver = get_chrome()1968 gg = 國家圖書館(1969 driver,1970 '國家圖書館',1971 "https://aleweb.ncl.edu.tw/F",1972 ISBN1973 )1974 driver.close()1975 worksheet.append_rows(gg.values.tolist())1976 return gg1977# ---------------------------------被獨立出來的世新----------------------------------------1978def 世新大學(driver, org, org_url, ISBN):1979 try:1980 driver.get(org_url)1981 search_ISBN(driver, ISBN, 'q')1982 table = accurately_find_table_and_read_it(driver, '#holdingst')1983 table['圖書館'], table['連結'] = org, driver.current_url1984 table = organize_columns(table)1985 except Exception as e:1986 print(f'在「{org}」找不到「{ISBN}」')1987 return1988 else:1989 table = statuss(table)1990 return table1991# 世新大學 SHU V OK1992def SHU(ISBN):1993 sheet = ggSheet()1994 worksheet = sheet.get_worksheet(0)1995 driver = get_chrome()1996 gg = 世新大學(1997 driver,1998 '世新大學',1999 "https://koha.shu.edu.tw/",2000 ISBN2001 )2002 driver.close()2003 worksheet.append_rows(gg.values.tolist())2004 return gg2005# 台北海洋科技大學 TUMT V2006def TUMT(ISBN):2007 sheet = ggSheet()2008 worksheet = sheet.get_worksheet(0)2009 driver = get_chrome()2010 gg = 台北海洋科技大學(2011 driver,2012 '台北海洋科技大學',2013 'http://140.129.253.4/webopac7/sim_data2.php?pagerows=15&orderby=BRN&pageno=1&bn=',2014 ISBN2015 )2016 driver.close()2017 worksheet.append_rows(gg.values.tolist())2018 return gg2019# ---------------------------------被獨立出來的敏實科大----------------------------------------2020def 敏實科技大學(driver, org, org_url, ISBN):2021 try:2022 table = []2023 driver.get(org_url)2024 search_ISBN(driver, ISBN, 'DB.IN1')2025 if wait_for_element_present(driver, 'span.sm9'):2026 search_result_message = BeautifulSoup(2027 driver.page_source, 'html.parser').find_all('span', 'sm9')[-2].text2028 search_result_regex = re.compile(r'\d')2029 mo = search_result_regex.search(search_result_message)2030 if int(mo.group()) == 0:2031 print(f'在「{org}」找不到「{ISBN}」')2032 return2033 driver.find_elements_by_tag_name('a')[1].click()2034 tgt = accurately_find_table_and_read_it(driver, 'table', -1)2035 tgt['圖書館'], tgt['連結'] = org, driver.current_url2036 table.append(tgt)2037 except Exception as e:2038 print(f'在「{org}」搜尋「{ISBN}」時,發生錯誤,錯誤訊息為:「{e}」!')2039 return2040 else:2041 table = organize_columns(table)2042 table = statuss(table)2043 return table2044# 敏實科技大學 MITUST2045def MITUST(ISBN):2046 sheet = ggSheet()2047 worksheet = sheet.get_worksheet(0)2048 driver = get_chrome()2049 gg = 敏實科技大學(2050 driver,2051 '敏實科技大學',2052 'http://120.105.200.52/xsearch-b.html',2053 ISBN2054 )2055 driver.close()2056 worksheet.append_rows(gg.values.tolist())2057 return gg2058# ------------------------------------------Primo-----------------------------------------2059# primo_crawler()2060# 臺大|政大|淡江|銘傳|東吳2061def primo_crawler(driver, org, url_front, ISBN, url_behind, tcn):2062 url = url_front + ISBN + url_behind2063 primo_lst = []2064 try:2065 # 進入《館藏系統》頁面2066 driver.get(url)2067 try: # 開始爬蟲2068 editions = wait_for_elements_present(2069 driver, 'item-title', 20, By.CLASS_NAME)2070 print("進入搜尋")2071 """2072 try: #找有沒有多個版本的箭頭2073 if org != "國立臺灣大學": #排除台大,不然台大沒辦法跑2074 edition_check = wait_for_element_clickable(2075 driver, "neutralized-button.arrow-link-button.md-button.md-primoExplore-theme.md-ink-ripple", 20, By.CLASS_NAME).click()2076 except:2077 edition_check = None2078 2079 if edition_check != None: #如果有箭頭,代表有多個版本,再爬一次版本!2080 print("有多個版本QQ")2081 time.sleep(5)2082 editions = wait_for_elements_present(2083 driver, 'item-title', 20, By.CLASS_NAME)2084 else:2085 editions[0].click()2086 print(edition_check)2087 """2088 2089 if len(editions) > 1: # 如果最外面有兩個版本(默認點進去不會再分版本了啦)(ex.政大 9789861371955),直接交給下面處理2090 pass2091 else: # 如果最外面只有一個版本,那有可能點進去還有再分,先click進去,再分一個版本跟多個版本的狀況2092 time.sleep(5)2093 editions[0].click()2094 if org == "國立政治大學" or org == "國立清華大學" or org == "國立陽明交通大學":2095 try:2096 editions = driver.find_elements_by_class_name(2097 'item-title', 10) # 這時候是第二層的分版本了!(ex.政大 9789869109321)2098 print("應該是有找到裡面的版本了啦")2099 except:2100 pass2101 2102 try: # 先找叉叉確定是不是在最裡層了2103 back_check = wait_for_element_present(2104 driver, "md-icon-button.close-button.full-view-navigation.md-button.md-primoExplore-theme.md-ink-ripple")2105 print("找叉叉成功,準備找表格")2106 except:2107 back_check = None2108 print("沒有叉叉,進版本迴圈")2109 2110 if back_check == None: # 多個版本才要再跑迴圈(找不到叉叉代表不在最裡面,可知不是一個版本)2111 print("進多個版本")2112 for i in range(0, len(editions)): # 有幾個版本就跑幾次,不管哪一層版本都適用2113 time.sleep(5)2114 into = editions[i].click()2115 print("版本" + str(i))2116 if org == "國立屏東科技大學" or org == "國立高雄餐旅大學":2117 primo_lst += primo_two_finding(driver, org)2118 else:2119 primo_lst += primo_finding(driver, org, tcn)2120 try:2121 back2 = wait_for_element_clickable(2122 driver, "md-icon-button.close-button.full-view-navigation.md-button.md-primoExplore-theme.md-ink-ripple").click()2123 except:2124 back2 = None2125 else: # 如果只有一個版本(有叉叉的意思),那前面已經click過了不能再做2126 if org == "國立屏東科技大學" or org == "國立高雄餐旅大學":2127 primo_lst += primo_two_finding(driver, org)2128 print(primo_lst)2129 else:2130 print("進一個版本的primo_finding")2131 primo_lst += primo_finding(driver, org, tcn)2132 print(primo_lst)2133 except:2134 print("爬蟲失敗")2135 except:2136 print("沒進網址")2137 table = pd.DataFrame(primo_lst)2138 table.rename(columns={0: '圖書館', 1: '館藏地', 2: '索書號',2139 3: '館藏狀態', 4: '連結'}, inplace=True)2140 table = statuss(table)2141 return table2142# 國立臺灣大學 NTU V2143def NTU(ISBN):2144 sheet = ggSheet()2145 worksheet = sheet.get_worksheet(0)2146 driver = get_chrome()2147 gg = primo_crawler(2148 driver,2149 '國立臺灣大學',2150 "https://ntu.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2151 ISBN,2152 "&tab=Everything&search_scope=MyInst_and_CI&vid=886NTU_INST:886NTU_INST&offset=0",2153 "layout-align-space-between-center.layout-row.flex-100"2154 )2155 driver.close()2156 worksheet.append_rows(gg.values.tolist())2157 return gg2158# 國立政治大學 NCCU V2159def NCCU(ISBN):2160 sheet = ggSheet()2161 worksheet = sheet.get_worksheet(0)2162 driver = get_chrome()2163 gg = primo_crawler(2164 driver,2165 '國立政治大學',2166 "https://nccu.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2167 ISBN,2168 "&tab=Everything&search_scope=MyInst_and_CI&vid=886NCCU_INST:886NCCU_INST",2169 "layout-align-space-between-center.layout-row.flex-100"2170 )2171 driver.close()2172 worksheet.append_rows(gg.values.tolist())2173 return gg2174# 淡江大學 TKU V OK2175def TKU(ISBN):2176 sheet = ggSheet()2177 worksheet = sheet.get_worksheet(0)2178 driver = get_chrome()2179 gg = primo_crawler(2180 driver,2181 '淡江大學',2182 "https://uco-network.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2183 ISBN,2184 "&tab=Everything&search_scope=MyInst_and_CI&vid=886UCO_TKU:886TKU_INST&lang=zh-tw&offset=0",2185 "neutralized-button.layout-full-width.layout-display-flex.md-button.md-ink-ripple.layout-row"2186 )2187 driver.close()2188 worksheet.append_rows(gg.values.tolist())2189 return gg2190# 銘傳大學 MCU V(索書號是空的) OK2191def MCU(ISBN):2192 sheet = ggSheet()2193 worksheet = sheet.get_worksheet(0)2194 driver = get_chrome()2195 gg = primo_crawler(2196 driver,2197 '銘傳大學',2198 "https://uco-mcu.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2199 ISBN,2200 "&tab=Everything&search_scope=MyInst_and_CI&vid=886UCO_MCU:886MCU_INST&lang=zh-tw&offset=0",2201 "md-2-line.md-no-proxy._md"2202 )2203 driver.close()2204 worksheet.append_rows(gg.values.tolist())2205 return gg2206# 東吳大學 SCU V OK2207def SCU(ISBN):2208 sheet = ggSheet()2209 worksheet = sheet.get_worksheet(0)2210 driver = get_chrome()2211 gg = primo_crawler(2212 driver,2213 '東吳大學',2214 "https://uco-scu.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2215 ISBN,2216 "&tab=Everything&search_scope=MyInst_and_CI&vid=886UCO_SCU:886SCU_INST&lang=zh-tw&offset=0",2217 "md-2-line.md-no-proxy._md"2218 )2219 driver.close()2220 worksheet.append_rows(gg.values.tolist())2221 return gg2222# 國立高雄科技大學 NKUST V OK2223def NKUST(ISBN):2224 sheet = ggSheet()2225 worksheet = sheet.get_worksheet(0)2226 driver = get_chrome()2227 gg = primo_crawler(2228 driver,2229 '國立高雄科技大學',2230 "https://nkust.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2231 ISBN,2232 "&tab=Everything&search_scope=MyInst_and_CI&vid=886NKUST_INST:86NKUST&lang=zh-tw&offset=0,",2233 "layout-align-space-between-center.layout-row.flex-100"2234 )2235 driver.close()2236 worksheet.append_rows(gg.values.tolist())2237 return gg2238# 國立清華大學 NTHU2239def NTHU(ISBN):2240 sheet = ggSheet()2241 worksheet = sheet.get_worksheet(0)2242 driver = get_chrome()2243 gg = primo_crawler(2244 driver,2245 '國立清華大學',2246 "https://nthu.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2247 ISBN,2248 "&tab=LibraryCatalog&search_scope=MyInstitution&vid=886UST_NTHU:886UST_NTHU&lang=zh-tw&offset=0",2249 "layout-align-space-between-center.layout-row.flex-100"2250 )2251 driver.close()2252 worksheet.append_rows(gg.values.tolist())2253 return gg2254# 國立陽明交通大學 NYCU2255def NYCU(ISBN):2256 sheet = ggSheet()2257 worksheet = sheet.get_worksheet(0)2258 driver = get_chrome()2259 gg = primo_crawler(2260 driver,2261 '國立陽明交通大學',2262 "https://nycu.primo.exlibrisgroup.com/discovery/search?query=any,contains,",2263 ISBN,2264 "&tab=Everything&search_scope=MyInst_and_CI&vid=886UST_NYCU:886UST_NYCU&lang=zh-tw&offset=0",2265 "layout-align-space-between-center.layout-row.flex-100"2266 )2267 driver.close()2268 worksheet.append_rows(gg.values.tolist())2269 return gg2270# ------------------------------------------Primo v2-----------------------------------------2271# primo_two_crawler()2272# 屏科大|高餐|高科大2273def primo_two_crawler(driver, org, url_front, ISBN, url_behind):2274 url = url_front + ISBN + url_behind2275 primo_two_lst = []2276 def primo_two_finding(org): # 爬資訊的def2277 sub_df_lst = []2278 time.sleep(2)2279 try:2280 back = driver.find_element_by_css_selector(2281 ".tab-header .back-button.button-with-icon.zero-margin.md-button.md-primoExplore-theme.md-ink-ripple")2282 except:2283 back = None2284 if back != None:2285 back.click()2286 similar_xpath = "/html/body/primo-explore/div[3]/div/md-dialog/md-dialog-content/sticky-scroll/prm-full-view/div/div/div[2]/div/div[1]/div[4]/div/prm-full-view-service-container/div[2]/div/prm-opac/md-tabs/md-tabs-content-wrapper/md-tab-content[2]/div/md-content/prm-location-items/div[2]/div[1]/p/span["2287 status = driver.find_element_by_xpath(similar_xpath + "1]")2288 place = driver.find_element_by_xpath(similar_xpath + "3]")2289 num = driver.find_element_by_xpath(similar_xpath + "5]")2290 now_url = driver.current_url2291 number = num.text.replace("(", "").replace(")", "")2292 new_row = [org, place.text, number, status.text, now_url]2293 sub_df_lst.append(new_row)2294 return sub_df_lst2295 try:2296 # 進入《館藏系統》頁面2297 driver.get(url)2298 # 等待"進階查詢的按鈕"直到出現:click2299 time.sleep(15)2300 try: # 開始爬蟲2301 editions = driver.find_elements_by_class_name('item-title', 20)2302 if len(editions) > 1: # 如果最外面有兩x`個版本(默認點進去不會再分版本了啦)(ex.政大 9789861371955),直接交給下面處理2303 pass2304 else: # 如果最外面只有一個版本,那有可能點進去還有再分,先click進去,再分一個版本跟多個版本的狀況2305 time.sleep(2)2306 editions[0].click()2307 time.sleep(5)2308 editions = driver.find_elements_by_class_name(2309 'item-title', 20) # 這時候是第二層的分版本了!(ex.政大 9789869109321)2310 try: # 先找叉叉確定是不是在最裡層了2311 back_check = driver.find_element_by_class_name(2312 "md-icon-button.close-button.full-view-navigation.md-button.md-primoExplore-theme.md-ink-ripple")2313 except:2314 back_check = None2315 if back_check == None: # 多個版本才要再跑迴圈(找不到叉叉代表不在最裡面,可知不是一個版本)2316 for i in range(0, len(editions)): # 有幾個版本就跑幾次,不管哪一層版本都適用2317 into = editions[i].click()2318 time.sleep(3)2319 primo_two_lst += primo_two_finding(org)2320 try:2321 back2 = driver.find_element_by_class_name(2322 "md-icon-button.close-button.full-view-navigation.md-button.md-primoExplore-theme.md-ink-ripple").click()2323 except:2324 back2 = None2325 else: # 如果只有一個版本(有叉叉的意思),那前面已經click過了不能再做2326 time.sleep(3)2327 primo_two_lst += primo_two_finding(org)2328 except:2329 pass2330 except:2331 pass2332 table = pd.DataFrame(primo_two_lst)2333 table.rename(columns={0: '圖書館', 1: '館藏地', 2: '索書號',2334 3: '館藏狀態', 4: '連結'}, inplace=True)2335 table = statuss(table)2336 return table2337# 國立屏東科技大學 NPUST V2338def NPUST(ISBN):2339 sheet = ggSheet()2340 worksheet = sheet.get_worksheet(0)2341 driver = get_chrome()2342 gg = primo_crawler(2343 driver,2344 '國立屏東科技大學',2345 "http://primo.lib.npust.edu.tw/primo-explore/search?institution=NPUST&vid=NPUST&tab=default_tab&search_scope=SearchAll&mode=basic&query=any,contains,",2346 ISBN,2347 "&displayMode=full&bulkSize=10&highlight=true&dum=true&lang=zh_TW&displayField=all&pcAvailabiltyMode=true",2348 ""2349 )2350 driver.close()2351 worksheet.append_rows(gg.values.tolist())2352 return gg2353# 國立高雄餐旅大學 NKUHT V2354def NKUHT(ISBN):2355 sheet = ggSheet()2356 worksheet = sheet.get_worksheet(0)2357 driver = get_chrome()2358 gg = primo_crawler(2359 driver,2360 '國立高雄餐旅大學',2361 "https://find.nkuht.edu.tw/primo-explore/search?query=any,contains,",2362 ISBN,2363 "&tab=default_tab&search_scope=%E6%9F%A5%E9%A4%A8%E8%97%8F&vid=NKUHT_N&offset=0",2364 ""2365 )2366 driver.close()2367 worksheet.append_rows(gg.values.tolist())2368 return gg2369# ------------------------------------------綠點點----------------------------------------------2370# primo_greendot_crawler()2371# 長庚|中正|長榮2372def primo_greendot_crawler(driver, org, url_front, ISBN, url_behind):2373 url = url_front + ISBN + url_behind2374 primo_greendot_lst = []2375 try:2376 driver.get(url)2377 try: # 只有一個版本2378 place_click = wait_for_element_clickable(2379 driver, 'exlidResult0-LocationsTab', 10, By.ID).click()2380 primo_greendot_lst += primo_greendot_finding(driver, org)2381 except: # 有多個版本,所以要點進去再做2382 manyeditions = wait_for_element_clickable(2383 driver, 'titleLink', 10, By.ID).click()2384 for i in range(1, 10): # 假設有十個版本吧2385 try:2386 id = 'exlidResult' + str(i) + '-LocationsTab'2387 place2_click = wait_for_element_clickable(2388 driver, id, 15, By.ID).click()2389 primo_greendot_lst += primo_greendot_finding(driver, org)2390 except:2391 continue2392 except:2393 pass2394 table = pd.DataFrame(primo_greendot_lst)2395 table.rename(columns={0: '圖書館', 1: '館藏地', 2: '索書號',2396 3: '館藏狀態', 4: '連結'}, inplace=True)2397 table = statuss(table)2398 return table2399# 長庚大學 CGU V OK2400def CGU(ISBN):2401 sheet = ggSheet()2402 worksheet = sheet.get_worksheet(0)2403 driver = get_chrome()2404 gg = primo_greendot_crawler(2405 driver,2406 '長庚大學',2407 "https://primo.lib.cgu.edu.tw/primo_library/libweb/action/search.do?fn=search&ct=search&initialSearch=true&mode=Advanced&tab=default_tab&indx=1&dum=true&srt=rank&vid=CGU&frbg=&tb=t&vl%2812508471UI0%29=isbn&vl%2812508471UI0%29=title&vl%2812508471UI0%29=isbn&vl%281UIStartWith0%29=contains&vl%28freeText0%29=",2408 ISBN,2409 "&vl%28boolOperator0%29=AND&vl%2812508474UI1%29=creator&vl%2812508474UI1%29=title&vl%2812508474UI1%29=creator&vl%281UIStartWith1%29=contains&vl%28freeText1%29=&vl%28boolOperator1%29=AND&vl%2812508470UI2%29=any&vl%2812508470UI2%29=title&vl%2812508470UI2%29=any&vl%281UIStartWith2%29=contains&vl%28freeText2%29=&vl%28boolOperator2%29=AND&vl%2812626940UI3%29=any&vl%2812626940UI3%29=title&vl%2812626940UI3%29=any&vl%281UIStartWith3%29=contains&vl%28freeText3%29=&vl%28boolOperator3%29=AND&vl%28D2240502UI4%29=all_items&vl%2853081356UI5%29=all_items&vl%28D2240500UI6%29=all_items&Submit=%E6%AA%A2%E7%B4%A2"2410 )2411 driver.close()2412 worksheet.append_rows(gg.values.tolist())2413 return gg2414# 國立中正大學 CCU V OK2415def CCU(ISBN):2416 sheet = ggSheet()2417 worksheet = sheet.get_worksheet(0)2418 driver = get_chrome()2419 gg = primo_greendot_crawler(2420 driver,2421 '國立中正大學',2422 "http://primo.lib.ccu.edu.tw/primo_library/libweb/action/search.do?fn=search&ct=search&initialSearch=true&mode=Advanced&tab=default_tab&indx=1&dum=true&srt=rank&vid=CCU&frbg=&tb=t&vl%28256032279UI0%29=isbn&vl%28256032279UI0%29=title&vl%28256032279UI0%29=any&vl%281UIStartWith0%29=contains&vl%28freeText0%29=",2423 ISBN,2424 "&vl%282853831UI0%29=AND&vl%28256032278UI1%29=any&vl%28256032278UI1%29=title&vl%28256032278UI1%29=any&vl%281UIStartWith1%29=contains&vl%28freeText1%29=&vl%282853829UI1%29=AND&vl%28256032320UI2%29=any&vl%28256032320UI2%29=title&vl%28256032320UI2%29=any&vl%281UIStartWith2%29=contains&vl%28freeText2%29=&vl%282853831UI2%29=AND&vl%28D2853835UI3%29=all_items&vl%28256032346UI4%29=all_items&vl%28D2853833UI5%29=all_items&Submit=%E6%AA%A2%E7%B4%A2"2425 )2426 driver.close()2427 worksheet.append_rows(gg.values.tolist())2428 return gg2429# 長榮大學 CJCU V OK2430def CJCU(ISBN):2431 sheet = ggSheet()2432 worksheet = sheet.get_worksheet(0)2433 driver = get_chrome()2434 gg = primo_greendot_crawler(2435 driver,2436 '長榮大學',2437 "http://discovery.lib.cjcu.edu.tw:1701/primo_library/libweb/action/search.do?fn=search&ct=search&initialSearch=true&mode=Advanced&tab=ils_pc&indx=1&dum=true&srt=rank&vid=CJCU&frbg=&tb=t&vl%28D2348462UI0%29=any&vl%28D2348462UI0%29=title&vl%28D2348462UI0%29=any&vl%281UIStartWith0%29=contains&vl%28freeText0%29=,",2438 ISBN,2439 "&vl%28boolOperator0%29=AND&vl%2812508474UI1%29=creator&vl%2812508474UI1%29=title&vl%2812508474UI1%29=creator&vl%281UIStartWith1%29=contains&vl%28freeText1%29=&vl%28boolOperator1%29=AND&vl%2812508470UI2%29=any&vl%2812508470UI2%29=title&vl%2812508470UI2%29=any&vl%281UIStartWith2%29=contains&vl%28freeText2%29=&vl%28boolOperator2%29=AND&vl%2812626940UI3%29=any&vl%2812626940UI3%29=title&vl%2812626940UI3%29=any&vl%281UIStartWith3%29=contains&vl%28freeText3%29=&vl%28boolOperator3%29=AND&vl%28D2240502UI4%29=all_items&vl%2853081356UI5%29=all_items&vl%28D2240500UI6%29=all_items&Submit=%E6%AA%A2%E7%B4%A2"2440 )2441 driver.close()2442 worksheet.append_rows(gg.values.tolist())2443 return gg2444# ----------------------------------------要一直點進去------------------------------------------2445# clickclick_crawler()2446# 馬偕醫|工研院|明志|長庚科大|清華|暨南|臺南大|兩廳院|台神2447def clickclick_crawler(driver, org, org_url, ISBN, xpath_num, gogo_xpath, xpath_detail, table_xpath, index_lst):2448 clickclick_lst = []2449 into_1_lst = ["馬偕醫學院", "工業技術研究院", "國立清華大學", "國立臺灣美術館", "國立臺灣史前文化博物館"]2450 try:2451 # 分三類的進入方式2452 driver.get(org_url)2453 if org in into_1_lst: # 那種類型的沒辦改網址進進階搜尋QQ2454 pro_search = wait_for_element_clickable(2455 driver, "進階查詢", 10, By.LINK_TEXT).click()2456 print("進入進階查詢")2457 # 換成ISBN搜尋,xpath_num2458 ISBN_xpath = "/html/body/form/table[1]/tbody/tr[2]/td[1]/select/option[" + xpath_num + "]"2459 use_ISBN = wait_for_element_clickable(2460 driver, ISBN_xpath, 10, By.XPATH).click()2461 print("下拉選單改ISBN")2462 search_input = wait_for_element_clickable(2463 driver, "request", 5, By.NAME)2464 search_input.send_keys(ISBN)2465 print("輸入ISBN")2466 gogo = wait_for_element_clickable(2467 driver, gogo_xpath, 5, By.XPATH).click() # 按下確定,gogo_xpath2468 print("點擊搜尋")2469 click_result = wait_for_element_clickable(2470 driver, "/html/body/form/table[1]/tbody/tr[2]/td[4]/a", 10, By.XPATH).click()2471 print("點擊搜尋結果的數字")2472 # 終於結束前面的輸入可以開始爬蟲了2473 try: # 暨南有"直接進去書的頁面"的案例,所以先用try避開看看2474 where2 = wait_for_element_clickable(2475 driver, "brieftit", 5, By.CLASS_NAME).click()2476 print("點擊書的條目")2477 except:2478 pass2479 if org == "國立暨南國際大學":2480 where3_xpath = "/html/body/table[9]/tbody/tr[1]/td[2]/a"2481 else:2482 # 按下書在哪裡?,xpath_detail2483 where3_xpath = "/html/body/table[9]/tbody/tr/td[1]/table/tbody/tr[1]/td[2]/" + xpath_detail2484 where3 = wait_for_element_clickable(2485 driver, where3_xpath, 5, By.XPATH).click()2486 print("點擊[書在哪裡?]")2487 table = wait_for_element_clickable(2488 driver, table_xpath, 5, By.XPATH) # 找表格位置,table_xpath2489 print("找到表格了")2490 trlist = table.find_elements_by_tag_name('tr')2491 now_url = driver.current_url2492 for row in trlist:2493 tdlist = row.find_elements_by_tag_name('td')2494 for sth in tdlist:2495 new_row = [org, tdlist[index_lst[0]].text,2496 tdlist[index_lst[1]].text, tdlist[index_lst[2]].text, now_url]2497 clickclick_lst.append(new_row)2498 break2499 print(clickclick_lst)2500 except:2501 print("總之是失敗了")2502 table = pd.DataFrame(clickclick_lst)2503 print("做成表格")2504 table.rename(columns={0: '圖書館', 1: '館藏地', 2: '索書號',2505 3: '館藏狀態', 4: '連結'}, inplace=True)2506 print("rename成功")2507 table = statuss(table)2508 return table2509# 馬偕醫學院 MMC V OK2510def MMC(ISBN):2511 sheet = ggSheet()2512 worksheet = sheet.get_worksheet(0)2513 driver = get_chrome()2514 gg = clickclick_crawler(2515 driver,2516 '馬偕醫學院',2517 "http://aleph.library.mmc.edu.tw/F?func=find-b&adjacent=Y&find_code=WRD&local_base=TOP02&request=&TY=",2518 ISBN,2519 "7",2520 "/html/body/form/table[1]/tbody/tr[7]/td/input",2521 "span/a[1]",2522 '/html/body/table[10]',2523 [2, 4, 7]2524 )2525 driver.close()2526 worksheet.append_rows(gg.values.tolist())2527 return gg2528# 工業技術研究院 ITRI V2529def ITRI(ISBN):2530 sheet = ggSheet()2531 worksheet = sheet.get_worksheet(0)2532 driver = get_chrome()2533 gg = clickclick_crawler(2534 driver,2535 '工業技術研究院',2536 "http://61.61.255.73/F?func=find-d-0",2537 ISBN,2538 "7",2539 "/html/body/form/table[1]/tbody/tr[9]/td/input",2540 "a/img",2541 '/html/body/table[10]',2542 [5, 2, 8]2543 )2544 driver.close()2545 worksheet.append_rows(gg.values.tolist())2546 return gg2547# 明志科技大學 MCUT V2548def MCUT(ISBN):2549 sheet = ggSheet()2550 worksheet = sheet.get_worksheet(0)2551 driver = get_chrome()2552 gg = clickclick_crawler(2553 driver,2554 '明志科技大學',2555 "https://aleph.lib.cgu.edu.tw/F/?func=find-d-0&local_base=FLY03",2556 ISBN,2557 "7",2558 "/html/body/form/table[1]/tbody/tr[9]/td/input",2559 "a",2560 '/html/body/table[9]',2561 [3, 4, 7]2562 )2563 driver.close()2564 worksheet.append_rows(gg.values.tolist())2565 return gg2566# 長庚科技大學 CGUST V2567def CGUST(ISBN):2568 sheet = ggSheet()2569 worksheet = sheet.get_worksheet(0)2570 driver = get_chrome()2571 gg = clickclick_crawler(2572 driver,2573 '長庚科技大學',2574 "https://aleph.lib.cgu.edu.tw/F/?func=find-d-0&local_base=FLY04",2575 ISBN,2576 "7",2577 "/html/body/form/table[1]/tbody/tr[9]/td/input",2578 "a",2579 '/html/body/table[9]',2580 [3, 4, 7]2581 )2582 driver.close()2583 worksheet.append_rows(gg.values.tolist())2584 return gg2585# 國立暨南國際大學 NCNU V2586def NCNU(ISBN):2587 sheet = ggSheet()2588 worksheet = sheet.get_worksheet(0)2589 driver = get_chrome()2590 gg = clickclick_crawler(2591 driver,2592 '國立暨南國際大學',2593 "https://aleph.lib.ncnu.edu.tw/F/?func=find-d-0",2594 ISBN,2595 "7",2596 "/html/body/form/table[1]/tbody/tr[9]/td/input",2597 "",2598 '/html/body/table[11]',2599 [3, 4, 7]2600 )2601 driver.close()2602 worksheet.append_rows(gg.values.tolist())2603 return gg2604# 國立臺南大學 NUTN V2605def NUTN(ISBN):2606 sheet = ggSheet()2607 worksheet = sheet.get_worksheet(0)2608 driver = get_chrome()2609 gg = clickclick_crawler(2610 driver,2611 '國立臺南大學',2612 "https://aleph.nutn.edu.tw/F/?func=find-d-0",2613 ISBN,2614 "7",2615 "/html/body/form/table[1]/tbody/tr[9]/td/input",2616 "a",2617 '/html/body/table[9]',2618 [2, 4, 8]2619 )2620 driver.close()2621 worksheet.append_rows(gg.values.tolist())2622 return gg2623# 國家兩廳院 NTCH 9573308436 V2624def NTCH(ISBN):2625 sheet = ggSheet()2626 worksheet = sheet.get_worksheet(0)2627 driver = get_chrome()2628 gg = clickclick_crawler(2629 driver,2630 '國家兩廳院',2631 "https://opac.npac-ntch.org/F/?func=find-d-0",2632 ISBN,2633 "13",2634 "/html/body/form/table[3]/tbody/tr/td/input",2635 "a[1]",2636 '/html/body/table[9]',2637 [3, 4, 7]2638 )2639 driver.close()2640 worksheet.append_rows(gg.values.tolist())2641 return gg2642# 台灣神學研究學院 TGST V2643def TGST(ISBN):2644 sheet = ggSheet()2645 worksheet = sheet.get_worksheet(0)2646 driver = get_chrome()2647 gg = clickclick_crawler(2648 driver,2649 '台灣神學研究學院',2650 "http://aleph.flysheet.com.tw/F/?func=find-d-0",2651 ISBN,2652 "7",2653 "/html/body/form/table[1]/tbody/tr[9]/td/input",2654 "a",2655 '/html/body/table[10]',2656 [3, 4, 8]2657 )2658 driver.close()2659 worksheet.append_rows(gg.values.tolist())2660 return gg2661# 國立臺灣美術館 NTMOFA 97848973765472662def NTMOFA(ISBN):2663 sheet = ggSheet()2664 worksheet = sheet.get_worksheet(0)2665 driver = get_chrome()2666 gg = clickclick_crawler(2667 driver,2668 '國立臺灣美術館',2669 "http://lib.moc.gov.tw/F?func=find-b-0&local_base=THM06",2670 ISBN,2671 "",2672 "a",2673 '/html/body/table[9]'2674 )2675 driver.close()2676 worksheet.append_rows(gg.values.tolist())2677 return gg2678# 高苑科技大學 KYU X (您所想要連結的資料庫目前維護中)2679def KYU(ISBN):2680 sheet = ggSheet()2681 worksheet = sheet.get_worksheet(0)2682 driver = get_chrome()2683 gg = clickclick_crawler(2684 driver,2685 '高苑科技大學',2686 "http://210.60.92.160/F?func=find-d-0",2687 ISBN,2688 "6",2689 "/html/body/form/table[1]/tbody/tr[8]/td/input",2690 "a",2691 '/html/body/table[8]',2692 [2, 4, 8]2693 )2694 driver.close()2695 worksheet.append_rows(gg.values.tolist())2696 return gg2697# ---------------------------------------難以形容|很有特色------------------------------------------------2698# chungchung_crawler()2699# 中臺|中州2700def chungchung_crawler(driver, org, org_url, ISBN):2701 driver.get(org_url)2702 search_input = wait_for_element_clickable(driver, "input", 5, By.NAME)2703 search_input.send_keys(ISBN)2704 gogo = wait_for_element_clickable(driver, "query", 5, By.NAME).click()2705 where = wait_for_element_clickable(2706 driver, "body > div > font > font > form > center:nth-child(1) > table > tbody > tr:nth-child(2) > td:nth-child(4) > font > a", 5, By.CSS_SELECTOR).click()2707 table = accurately_find_table_and_read_it(driver, "table", table_index=3)2708 table = organize_columns(table)2709 table.drop([0], inplace=True)2710 table = statuss(table)2711 return table2712# 中臺科技大學 CTUST2713def CTUST(ISBN):2714 sheet = ggSheet()2715 worksheet = sheet.get_worksheet(0)2716 driver = get_chrome()2717 gg = chungchung_crawler(2718 driver,2719 '中臺科技大學',2720 "http://120.107.56.24/isbn1.htm",2721 ISBN2722 )2723 driver.close()2724 worksheet.append_rows(gg.values.tolist())2725 return gg2726# 中州科技大學 CCUST2727def CCUST(ISBN):2728 sheet = ggSheet()2729 worksheet = sheet.get_worksheet(0)2730 driver = get_chrome()2731 gg = chungchung_crawler(2732 driver,2733 '中州科技大學',2734 "http://163.23.234.194/isbn1.htm",2735 ISBN2736 )2737 driver.close()2738 worksheet.append_rows(gg.values.tolist())2739 return gg2740# 靖的jsp2741def jing_jsp_crawler(driver, org, org_url, ISBN):2742 function = sys._getframe().f_code.co_name2743 alert_execution_report(function, 100)2744 try:2745 table = []2746 driver.get(org_url)2747 try:2748 select_ISBN_strategy(driver, 'search_field', 'ISBN')2749 except:2750 select_ISBN_strategy(driver, 'search_field', 'STANDARDNO') # 北科大2751 search_ISBN(driver, ISBN, 'search_input')2752 # 一筆2753 if wait_for_element_present(driver, 'table.order'):2754 i = 02755 while True:2756 try:2757 datatable = driver.find_element_by_class_name("order")2758 trlist = datatable.find_elements_by_tag_name('tr')2759 df_lst = []2760 for row in trlist:2761 tdlist = row.find_elements_by_tag_name('td')2762 for sth in tdlist:2763 new_row = [org, tdlist[2].text, tdlist[3].text,2764 tdlist[5].text, driver.current_url]2765 df_lst.append(new_row)2766 table.append(df_lst)2767 print(df_lst)2768 wait_for_element_clickable(driver, str(2+i), 2).click()2769 i += 12770 time.sleep(0.5)2771 except:2772 break2773 # 多筆、零筆2774 elif wait_for_element_present(driver, 'iframe#leftFrame'):2775 iframe = driver.find_element_by_id('leftFrame')2776 driver.switch_to.frame(iframe)2777 time.sleep(1.5) # 切換到 <frame> 需要時間,否則會無法讀取2778 # 判斷是不是"零筆"查詢結果2779 if wait_for_element_present(driver, '#totalpage').text == '0':2780 alert_exception_report(function, 'not found book')2781 return2782 # "多筆"查詢結果2783 tgt_urls = get_all_tgt_urls(driver)2784 for tgt_url in tgt_urls:2785 driver.get(tgt_url)2786 # 等待元素出現,如果出現,那麼抓取 DataFrame;如果沒出現,那麼跳出迴圈2787 if wait_for_element_present(driver, 'table.order'):2788 i = 02789 while True:2790 try:2791 datatable = driver.find_element_by_class_name(2792 "order")2793 trlist = datatable.find_elements_by_tag_name('tr')2794 df_lst = []2795 for row in trlist:2796 tdlist = row.find_elements_by_tag_name('td')2797 for sth in tdlist:2798 new_row = [2799 org, tdlist[2].text, tdlist[3].text, tdlist[5].text, driver.current_url]2800 df_lst.append(new_row)2801 table.append(df_lst)2802 print(df_lst)2803 wait_for_element_clickable(2804 driver, str(2+i), 2).click()2805 i += 12806 time.sleep(0.5)2807 except:2808 break2809 else:2810 continue2811 table = pd.DataFrame(table)2812 print(table)2813 table.rename(columns={0: '圖書館', 1: '館藏地', 2: '索書號',2814 3: '館藏狀態', 4: '連結'}, inplace=True)2815 except Exception as e:2816 alert_exception_report(function, e, 100)2817 return2818 else:2819 alert_completion_report(function, 100)2820 return table2821# ___________________________________________________2822# 新北市 NewTaipeiCity2823def NewTaipeiCity(ISBN):2824 sheet = ggSheet()2825 worksheet = sheet.get_worksheet(0)2826 driver = get_chrome()2827 all_Insts = []2828 all_Insts.append(2829 webpac_ajax_crawler(2830 driver,2831 '新北市立圖書館',2832 "https://webpac.tphcc.gov.tw/webpac/search.cfm",2833 ISBN2834 )2835 )2836 all_Insts.append(2837 toread_crawler(2838 driver,2839 '東南科技大學',2840 "http://140.129.140.176/toread/opac",...

Full Screen

Full Screen

nqueens.py

Source:nqueens.py Github

copy

Full Screen

...13 bit = random.randint(0, 1)14 self.chromosome += str(bit)15 else:16 self.chromosome = str(chrome)17 def get_chrome(self):18 return self.chromosome19 def fitness_function(self):20 fitness_sum = 021 for ver in range(0, self.chromosome_len, self.queen_len):22 first_queen = self.chromosome[ver: ver + self.queen_len]23 for hor in range(0, self.chromosome_len, self.queen_len):24 second_queen = self.chromosome[hor: hor + self.queen_len]25 if first_queen == second_queen and ver != hor:26 fitness_sum += 127 if ver != hor and (math.fabs(int(first_queen, 2) - int(second_queen, 2)) ==28 math.fabs(hor / self.queen_len - ver / self.queen_len)):29 fitness_sum += 130 fitness_sum = 8 - fitness_sum / 831 return fitness_sum32 def visualisation(self):33 solution = str()34 visual = str()35 for horizontal in range(0, self.chromosome_len, self.queen_len):36 queen = self.chromosome[horizontal:horizontal + self.queen_len]37 solution += str(int(queen, 2))38 for cell in range(self.queens_number * self.queens_number):39 if cell % 8 == 0:40 visual += '\n'41 if cell % 8 == int(solution[cell // 8]):42 visual += 'Q'43 else:44 visual += '+'45 return visual46class Solver_8_queens:47 def __init__(self, pop_size=100, cross_prob=0.7, mut_prob=0.25):48 self.pop_size = pop_size49 self.cross_prob = cross_prob50 self.mut_prob = mut_prob51 self.population = [Individual() for i in range(pop_size)]52 self.fitness_list = list()53 for ind in self.population:54 self.fitness_list.append(ind.fitness_function())55 def roulette_wheel(self):56 probability = list()57 ind_position = [i for i in range(self.pop_size)]58 fitness_sum = float()59 parents = list()60 for ind in self.fitness_list:61 fitness_sum += ind62 for i in self.fitness_list:63 choose_chance = i / fitness_sum64 probability.append(choose_chance)65 selected_individuals = numpy.random.choice(ind_position, self.pop_size, True, probability)66 for ind in selected_individuals:67 parents.append(self.population[ind])68 return parents69 def reproduce(self, parents):70 chromosome_len = self.population[0].chromosome_len71 next_generation = list()72 for pair in range(len(parents)//2):73 first_parent, second_parent = random.randint(0, len(parents) - 1), random.randint(0, len(parents) - 1)74 while first_parent == second_parent:75 second_parent = random.randint(0, len(parents) - 1)76 cross_prob = random.random()77 if cross_prob <= self.cross_prob:78 cross_point = random.randrange(chromosome_len)79 first_child = Individual(parents[first_parent].get_chrome()[0:cross_point] +80 parents[second_parent].get_chrome()[cross_point:chromosome_len])81 second_child = Individual(parents[second_parent].get_chrome()[0:cross_point] +82 parents[first_parent].get_chrome()[cross_point:chromosome_len])83 else:84 first_child, second_child = parents[first_parent], parents[second_parent]85 next_generation.append(first_child)86 next_generation.append(second_child)87 return next_generation88 def mutation(self, next_generation):89 chromosome_len = self.population[0].chromosome_len90 for ind in range(len(next_generation)):91 if random.random() <= self.mut_prob:92 mutated = random.randrange(chromosome_len)93 mutation = '0'94 if next_generation[ind].get_chrome()[mutated] == '0':95 mutation = '1'96 next_generation[ind] = Individual(next_generation[ind].get_chrome()[0:mutated] + mutation +97 next_generation[ind].get_chrome()[mutated + 1:chromosome_len])98 else:99 next_generation[ind] = Individual(next_generation[ind].get_chrome()[0:mutated] + mutation +100 next_generation[ind].get_chrome()[mutated + 1:chromosome_len])101 return next_generation102 def best_fitness(self):103 best_fitness = max(self.fitness_list)104 best_individual = self.fitness_list.index(best_fitness)105 return best_fitness, best_individual106 def proceed(self):107 parents = self.roulette_wheel()108 next_generation = self.reproduce(parents)109 next_generation = self.mutation(next_generation)110 self.population = next_generation111 for ind in range(len(self.population)):112 self.fitness_list[ind] = self.population[ind].fitness_function()113 def solve(self, min_fitness=7.9, max_epochs=3000):114 best_fitness, best_individual = self.best_fitness()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful