| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
使用
实例
import time
from PIL import Image
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import chaojiying
def main():
driver = webdriver.Ie()
driver.get("https://inv-veri.chinatax.gov.cn/")
wait = WebDriverWait(driver, 20)
wait.until(EC.presence_of_element_located((By.XPATH, '//tr/td/input[@id="fpdm"]'))).send_keys("041001900111")
wait.until(EC.presence_of_element_located((By.XPATH, '//tr/td/input[@id="fphm"]'))).send_keys("46160592")
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="kprq"]'))).send_keys("20191225")
wait.until(EC.presence_of_element_located((By.XPATH, '//tr/td/input[@id="kjje"]'))).send_keys("678071")
# selenium操作ie浏览器的click()不起作用,只能使用js点击方式
# 点击加载图片验证码
# driver.execute_script('document.getElementById("yzm_img").click()')
driver.execute_script('document.getElementById("yzm_img").click()')
time.sleep(2)
# yzm_code = input("请输入验证码:\t")
# wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="yzm"]'))).send_keys(yzm_code)
# # 点击查验按钮
# driver.execute_script('document.getElementsByClassName("blue_button")[0].click()')
yzm_position = driver.find_element_by_xpath('//*[@id="yzm"]')
size = yzm_position.size
location = yzm_position.location
print(location, size)
cp_position = (
location['x']-15,
location['y'],
location['x'] + size['width'] + 230,
location['y'] + size['height'] + 80
)
# print(f"验证码四边坐标左上{location['x'], location['y']}\t"
# f"右上{location['x']+size['width'], location['y']}\t"
# f"左下{location['x'], location['y']+size['height']}\t"
# f"右下{location['x']+size['width'], location['y']+size['height']}")
driver.save_screenshot("a.png")
image = Image.open('a.png')
image_pic = image.crop(cp_position)
image_pic.save("b.png")
c = chaojiying.Chaojiying_Client()
im = open("b.png", "rb").read()
yzm_code = c.PostPic(im, 5000)['pic_str']
print(yzm_code)
input("回车继续")
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="yzm"]'))).send_keys(yzm_code)
driver.execute_script('document.getElementsByClassName("blue_button")[0].click()')
if __name__ == '__main__':
main()| Back | FazBrowse Home | New Git URL |