How to get material parameter by name, and check if texture is assigned to parameter
I am going to link this here as intro:

Control Cycles material nodes and material properties in Python

To see what and if something is connected to your Kd socket:

kd_socket = nodes["Matte"].inputs[0]
# you can check if kd_socket.name returns "Kd"
# and kd_socket.type returns 'RGBA'

links = mat.node_tree.links
link = next(l for l in links if l.to_socket == kd_socket)
if link:
    image = link.from_node.image          # = bpy.data.images['Name']


In Blender everything is referenced by names, they are unique by design. If you don't know the name, you need to search through all items and pick what you want based on some criteria. You can recognize nodes by:


type: link.from_node.type         # 'TEX_IMAGE'
number of inputs/outputs, type of sockets, etc.
how the nodes are linked with links


You get the node class with:

mat.node_tree.nodes["Diffuse"].bl_idname
# 'ShaderNodeBsdfDiffuse'