def IdentifyVerifyCode(imgPath,getPublicSetting=True, base64_str = None): import base64 import os import Public.SettingReader as SettingReader encoded_string="" if base64_str is None : with open(imgPath, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) else: encoded_string = base64_str import requests req=requests.session() header={ 'content-type': 'raw;text/plain;charset=UTF-8;application/json' } req.headers.update(header) data="{'pic':"+str(encoded_string).lstrip('b')+", 'lang':'"+SettingReader.getPublicSetting("Identify","lang")+"'}" if (getPublicSetting): IdentifyServer=SettingReader.getPublicSetting("Identify","server") else: IdentifyServer=SettingReader.getSetting("Identify","server") res=req.post(IdentifyServer,data=data) import json result=json.loads(res.text) status=result["status"] if status != "-1": VerifyCode=result["result"].replace('\\','').replace('\n','').replace('|','') imgName=VerifyCode+"_"+result["serialNubmer"]+".png" os.rename(imgPath,os.path.join(os.getcwd(),"tempFolder",imgName)) return imgName raise Exception("驗證碼取得失敗")
def __init__(self, secName=None,publicSetting=False): if secName is None: secName="connect" if publicSetting: self.server = SettingReader.getPublicSetting(secName,"server") self.database = SettingReader.getPublicSetting(secName,"database") self.username = SettingReader.getPublicSetting(secName,"username") self.password = SettingReader.getPublicSetting(secName,"password") self.driver=SettingReader.getPublicSetting(secName,"driver") self.dbcon=None else: self.server = SettingReader.getSetting(secName,"server") self.database = SettingReader.getSetting(secName,"database") self.username = SettingReader.getSetting(secName,"username") self.password = SettingReader.getSetting(secName,"password") self.driver=SettingReader.getSetting(secName,"driver") self.dbcon=None
def getWebDriver(WebDriverType, incognito=True, headless=False, loadPic=True, DataFolderName=""): from selenium import webdriver from selenium.webdriver.chrome.options import Options import os from Public import SettingReader #filepath=os.getcwd() opts = Options() if incognito: opts.add_argument("--incognito") # 使用無痕模式 if not headless: opts.add_argument("--headless") #無介面模式 if DataFolderName == "": DataFolderName = createID() DataFolder = os.path.join(getSysTempFolder(), "PyJob", DataFolderName) opts.add_argument("user-data-dir=" + DataFolder) #變更資料儲存位置 #禁止載入圖片模式 if not loadPic: prefs = {"profile.managed_default_content_settings.images": 2} opts.add_experimental_option("prefs", prefs) opts.add_argument("--disable-gpu") #取消硬體加速 (規避google bug) opts.add_argument("--disable-extensions") #關閉擴充功能 opts.add_argument("--no-sandbox") #取消沙盒模式 WebDriverType = WebDriverType.lower() driver = None if WebDriverType == "chrome": driverPath = SettingReader.getPublicSetting( "WebDriver", "chrome" ) + "/chromedriver" #os.path.join(filepath,"Program","chromedriver.exe") driver = webdriver.Chrome(executable_path=driverPath, chrome_options=opts) return driver
jobURL = str(jsondata["jobURL"]) jobAREA = str(jsondata["jobAREA"]) companyInfo = jsondata["companyInfo"] try: companyName = PublicFun.SQLFilter(str(companyInfo["companyName"])) except Exception as ex: companyInfo = PublicFun.StringToJson(companyInfo, Default=False) companyName = PublicFun.SQLFilter(str(companyInfo["companyName"])) ScanDate = str(jsondata["ScanDate"]) DBConnect = SQLConnect.DBConnect(publicSetting=True) DBConnect.ConnectDB() CompanyGUID = BIASDataIO.CheckCompanyMappingList( DBConnect, companyName) requestHost = SettingReader.getSetting("global", "requestHost") req = RequestsHandler.getNewRequests(jobURL, requestHost) res = req.get(jobURL) res.encoding = 'utf8' JobSoup = bs(res.text, "html.parser") objJob = Engine.Query(DBConnect, JOB.JOBAAA(), "JOBAAA009 = '" + jobURL.strip() + "'") if (objJob.GUID == ""): objJob.GUID = PublicFun.createID() objJob.D_INSERTUSER = "******" else: objJob.D_MODIFYUSER = "******" objJob.JOBAAA001 = CompanyGUID objJob.JOBAAA002 = "104" objJob.JOBAAA003 = jobName.strip() objJob.JOBAAA005 = jobAREA.strip()
return version.strip() def write_json(file_path, data): with open(file_path, "w") as f: json.dump(data, f, indent=2) def read_json(file_path): with open(file_path, "r") as f: data = json.load(f) return data CHROME_DRIVER_BASE_URL = "https://chromedriver.storage.googleapis.com" CHROME_DRIVER_FOLDER = SettingReader.getPublicSetting( "WebDriver", "chrome") #r"E:\chromeDriver" CHROME_DRIVER_MAPPING_FILE = r"{}\mapping.json".format(CHROME_DRIVER_FOLDER) CHROME_DRIVER_EXE = r"{}\chromedriver.exe".format(CHROME_DRIVER_FOLDER) CHROME_DRIVER_ZIP = r"{}\chromedriver_win32.zip".format(CHROME_DRIVER_FOLDER) def get_chrome_driver_major_version(): chrome_browser_path = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" chrome_ver = get_file_version(chrome_browser_path) chrome_major_ver = chrome_ver.split(".")[0] return chrome_major_ver def get_latest_driver_version(browser_ver): latest_api = "{}/LATEST_RELEASE_{}".format(CHROME_DRIVER_BASE_URL, browser_ver)
JobID = sys.argv[1] data = sys.argv[2] jsondata = PublicFun.StringToJson(data) DBConnect = SQLConnect.DBConnect(publicSetting=True) DBConnect.ConnectDB() sql = "" if "Update" in jsondata: sql = ( "select GUID,JOBAAA009 from JOBAAA with(nolock) where JOBAAA029 != 'Y'" ) elif "Insert" in jsondata: sql = ( "select GUID,JOBAAA009 from JOBAAA with(nolock) where JOBAAA029 != 'Y'" ) else: raise Exception("無動作指令") CatchListPath = SettingReader.getSetting("excutePath", "CatchList") rows = DBConnect.GetDataTable(sql) for row in rows: tmpQueue = QueueIO.setParameter("CompanyGUID", row.GUID) tmpQueue = QueueIO.setParameter("JOBAAA009", row.JOBAAA009, tmpQueue) QueueIO.addQueue("UpdateJobEndRecruit", "Excute", CatchListPath, "UpdateJobEndRecruit.py", tmpQueue) DBConnect.close() except Exception as ex: print(ex)
Soup = bs(Chromedriver.page_source, "html.parser") pageSize=len(Soup.select("select.b-clear-border.js-paging-select.gtm-paging-top option")) if pageSize==0: pageSize=len(Soup.select("select.page-select.js-paging-select.gtm-paging-top option")) PublicFun.closeWebDriver(JobID,Chromedriver) return pageSize if __name__ == '__main__': jsondata="" try: JobID=sys.argv[1] data=sys.argv[2] jsondata = PublicFun.StringToJson(data) if "UpdateJobCategory" in jsondata and str(jsondata["UpdateJobCategory"])=="True": UpdateJobCategoryQueue=QueueIO.setParameter("","") UpdateJobCategoryPath=SettingReader.getSetting("excutePath","UpdateJobCategory") QueueIO.addQueue("Update104JobCategory","Excute",UpdateJobCategoryPath,"UpdateJobCategory.py",UpdateJobCategoryQueue) requestHost=SettingReader.getSetting("global","requestHost") CatchListPath=SettingReader.getSetting("excutePath","CatchList") SearchURL=SettingReader.getSetting("global","searchURL") if "condition" in jsondata: jsondata=jsondata["condition"] if "jobcats" in jsondata: for jobcat in jsondata["jobcats"]: condition="&jobcat="+jobcat JobWebSite=SearchURL+condition pageSize=getPageSize(JobWebSite+"&page=1") for n in range(pageSize): CatchListQueue=QueueIO.setParameter("URL",JobWebSite+"&page="+str(n+1))
today = datetime.datetime.now() ScanDate = today + datetime.timedelta(days=StandardDate) result = str(ScanDate.year).zfill(4) + "/" + str( ScanDate.month).zfill(2) + "/" + str(ScanDate.day).zfill(2) return result if __name__ == '__main__': jsondata = "" try: JobID = sys.argv[1] data = sys.argv[2] jsondata = PublicFun.StringToJson(data) ListURL = str(jsondata["URL"]) CatchCompanyPath = SettingReader.getSetting("excutePath", "CatchCompany") CatchJobPath = SettingReader.getSetting("excutePath", "CatchJob") DateStandard = int(SettingReader.getSetting("global", "DateStandard")) requestHost = SettingReader.getSetting("global", "requestHost") req = RequestsHandler.getNewRequests(ListURL, requestHost) res = req.get(ListURL) res.encoding = 'utf8' Soup = bs(res.text, "html.parser") JobContent = Soup.find("div", id="js-job-content") if JobContent is not None: JobContent = JobContent.select("article.js-job-item ul") ScanDate = getDataDate(DateStandard) for tempContent in JobContent: if tempContent.attrs is not None and len(