分类 Codes 下的文章

#coding:utf-8
from selenium import webdriver
import time
import os
import sys
from selenium.webdriver.firefox.options import Options
import requests

options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options)
driver.get('https://feng.cmd.gd/')
driver.set_page_load_timeout(30)
hiname = driver.find_element_by_xpath("//div[@id='chart']//p[@class='chart z']//a[@class='xi2']").text
userimg = '/web/wwwroot/default/' + hiname + '.png'
if not os.path.isfile(userimg):
    driver.find_element_by_xpath("//div[@id='chart']//p[@class='chart z']//a[@class='xi2']").click()
    time.sleep(2)
    driver.switch_to_window(driver.window_handles[1])
    driver.save_screenshot(userimg)
    #---upload image
    smms = 'https://sm.ms/api/upload'
    files = {'smfile': open(userimg, 'rb')}
    response = requests.post(smms, files=files)
    imgurl = response.json()
    print imgurl
    wtxt = open('/web/wwwroot/default/upload.txt', 'a')
    wtxt.write(str(imgurl))
    wtxt.close()

driver.quit()   #quit-firefox-drive
sys.exit(0)