原创 python3設置默認pip源

在具有python env下執行以下命令: pip config set global.trusted-host  mirrors.aliyun.com pip config set global.index-url http://mir

原创 xpath無法解析部分javascript獲取結果爲空問題

在工作中,碰到在頁面中html爲xpath可解析的格式,但是在實際腳本獲取中卻獲取不到的情況,通過查看網頁源代碼發現該部分內容爲<script>標籤對嵌入頁面顯示 <span id=***>****html中script內容****</s

原创 python利用裝飾器打印日誌、打印報錯UnicodeEncodeError

裝飾器  import logging def use_logging_with_multi_param(fun): def wrapper(*args): logging.warning('[%s is r

原创 python3 post json數據類型請求

     注意問題:post請求頭headers 要傳入Content-Type,data要與請求頭中的數據類型保持一致。區別於get請求,參數是加在url後面,可以用字典類型,requests中參數爲params。 import re

原创 win10右擊菜單添加在此處打開cmd命令窗口

複製下面的代碼段中的內容到txt文本中 另存爲以.reg結尾的文件(cmd.reg),並且編碼類型設置爲UTF-16LE(Unicode防止中文亂碼) 雙擊運行cmd.reg Windows Registry Editor Versi

原创 爬蟲解析庫:XPath

from lxml import etree from fake_useragent import UserAgent from urllib import parse import requests class TBImage()

原创 使用getopt命令規範shell腳本的命令行選項

#!/bin/bash log() { msg=$1 time=$(date "+%Y-%m-%d %H:%M:%S" ) echo "${time}|${msg}" } usage() { cat <<EOF U

原创 shell小命令大用處

一、獲取主機eth0網卡ip 1.ip a s eth0 |sed -nr "/inet .*/s/.*inet (.*)\/.*/\1/p" 2.ip a s eth0 |grep -Eo "([0-9]{1,3}\.){1,3}[0

原创 Shell腳本之入侵檢測報告

#!/bin/bash #main application:入侵報告生成工具,以auth.log作爲日誌文件爲例 AUTHLOG=/var/log/auth.log if [[ -n $1 ]];then AUTHLOG=$1

原创 Shell while read

#!/bin/bash set -x function rm OldRelease(){ awk -F "/" '{print $13}' release.log >> tmp.txt while read line

原创 Selenium+Chrome

1.由於新版Selenium不支持PhantomJS,所需chromedriver插件需要下載和本地Chrome瀏覽器同一個版本,並放到本地Chrome瀏覽器安裝目錄和Python安裝根目錄: chromedriver:http://np

原创 Python類的實現(單實例、初始化一次)

 注:先調用__new__方法,後通過__init__初始化。 class Char(object): __instance = None __flag = None def __new__(cls, name

原创 Python時間方法彙總

Python3獲取時間方法: 1.from datetime import datetime T1 = datetime.now().strftime('%Y-%m-%d %H:%M:%S') print(T1

原创 Python發送郵件

#!/usr/bin/python import sys import glob import codecs import smtplib import mimetypes from os.path import basename, j

原创 maven組合服務pom

<?xml version="1.0" encoding="UTF-8"?> <!-- ~ Copyright (c) zc Technologies Co., Ltd. 2018-2019. All rights reserved.