1.python部分解释学习。

2.ubuntu 需要 安装python

2.1 安装chrome最新版本

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo apt-get install ./google-chrome-stable_current_amd64.deb

google-chrome --version #查看版本号

2.2 安装chromedriver(安装相近版本就行)

下载链接:https://registry.npmmirror.com/binary.html?path=chromedriver/

unzip chromedriver_linux64.zip #解压文件

sudo mv -f chromedriver /usr/local/share/chromedriver

sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver

sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

chromedriver --version #查看版本号

2.3 安装虚拟界面(无需打开界面)

sudo apt-get install xvfb

2.4 安装需要的环境selenium和webdriver

pip install selenium

pip install webdriver

3.无界面例子

chrome_opt = Options() # 创建参数设置对象.

chrome_opt.add_argument('--headless') # 无界面化.

chrome_opt.add_argument('--disable-gpu') # 配合上面的无界面化.

chrome_opt.add_argument('--window-size=1366,768') # 设置窗口大小, 窗口大小会有影响.

chrome_opt.add_argument("--no-sandbox") #使用沙盒模式运行

# 创建Chrome对象并传入设置信息.

chromedriver_path = 'usr\bin\chromedriver.exe' #路径

driver = webdriver.Chrome(chromedriver_path, chrome_options=chrome_opt)

browser = webdriver.Chrome(chrome_options=chrome_opt)

url = "https://www.baidu.com/"

browser.get(url)

print()

4.使用webdriver.find_element

driver.find_element(By.ID,"username").send_keys("填写用户名") #username与网页id元素相同

driver.find_element(By.ID,"password").send_keys("填写密码") #与上同理

loginbnt=driver.find_element(By.ID,"Btn_LoginIn") #点击按钮id元素

loginbnt.click() #执行点击

5.element的xpath路径

网页审查可以直接复制完整路径

例如:/html/body/form/div[4]/div[2]/div[1]/table/tbody/tr[12]

6.微信消息推送使用pushplus

def send_notice(content):

token = "你的token"

title = "标题文本"

url = f"http://www.pushplus.plus/send?token={token}&title={title}&content={content}&template=html"

response = requests.request("GET", url)

print(response.text)

send_notice(发送文本内容)

7.利用宝塔脚本定时执行py文件。