欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

发票

程序员文章站 2022-06-03 17:49:26
...
import time
from selenium import webdriver
from pyvirtualdisplay import Display
from PIL import Image
from selenium.webdriver.common.alert import Alert

def Spider():
    print('正在检测页面..')
    # display = Display(visible=0, size=(1200, 800))
    # display.start()

    driver=webdriver.Chrome()
    driver.get(url='https://inv-veri.chinatax.gov.cn/')
    driver.set_window_size(1200, 800)

    # driver.save_screenshot('./inv.png')
    driver.find_element_by_xpath('//tr[1]/td[2]/input[@id="fpdm"]').send_keys('3300171130')
    driver.find_element_by_xpath('//tr[2]/td[2]/input[@id="fphm"]').send_keys('01236355')
    driver.find_element_by_xpath('//input[@id="kprq"]').send_keys('20170719')
    driver.find_element_by_xpath('//input[@id="kjje"]').send_keys('34.1')
    time.sleep(1)
    ac=driver.find_element_by_xpath('//td[@id="yzminfo"]')
    print(ac.text)

    # time.sleep(2)
    #获取截图
    driver.get_screenshot_as_file('verficode/3.png')

    #获取指定元素位置
    element = driver.find_element_by_id('yzm_img')
    left = int(element.location['x'])
    top = int(element.location['y'])
    right = int(element.location['x'] + element.size['width'])
    bottom = int(element.location['y'] + element.size['height'])

    #通过Image处理图像
    im = Image.open('verficode/3.png')
    im = im.crop((left, top, right, bottom))
    im.save('verficode/code4.png')

    print("请查看验证码..")
    # img = Image.open("verficode/code4.png")
    # img.show()

    yzm=str(input('请输入验证码:'))
    driver.find_element_by_xpath('//input[@id="yzm"]').send_keys(yzm)
    driver.find_element_by_xpath('//button[@id="checkfp"]').click()
    time.sleep(2)
    #定位iframe
    # driver.switch_to.frame("dialog-body")
    # cxcs=driver.find_element_by_xpath('//span[@id="cycs"]|//[id="popup_message"]')
    # print(cxcs.text)

    a=driver.find_element_by_xpath('//div[@id="popup_message"]')
    print(a.text)
    time.sleep(2)

    # a.accept()
    # 获取网页源代码
    # content = driver.page_source.encode('utf-8')



if __name__ == '__main__':
    s=Spider()