# print('========= 產生url座標:', location, '===========') lst_location.append(location) url_new = url_base + location longitude += longitude_step yield url_new latitude += latitude_step longitude = longitude_min logger.error('座標已全數跑完') bComplete = True return '' except Exception as e: logger.error(e) # =========== global 所需變數 ================= logger = create_logger(keyword + '/' + city) # 在 logs 目錄下建立 tutorial 目錄 logger.info('Start') start_time = time.time() lst_store = lst_store_csv = lst_review = [] dic_store = dic_review = {} bfinal = bError = bComplete = False page = notcity_count = restart = restart_limit = 0 district = folder = stores_path = url_location = '' folder_key_city = './csv/' + keyword + '/' + city + '/' if not os.path.exists(folder_key_city): os.makedirs(folder_key_city) # ===========================================
from logs.logger import create_logger import requests requests.packages.urllib3.disable_warnings() # 關閉警告訊息 def main(logger): url = "https://tw.yahoo.com/" headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' } results = requests.get(url, verify=False, headers=headers) results.encoding = 'utf-8' # 修改編碼 data = results.text logger.info(data) # 將 yahoo html 記到 log file 中 if __name__ == '__main__': logger = create_logger('tutorial') # 在 logs 目錄下建立 tutorial 目錄 logger.info('Start \n') try: main(logger) except Exception as e: logger.exception("Runtime Error Message:") logger.info("Export Done! \n")