I agree with the assertion that you should use Ctrl+Ins or dumpbin
.
However, what you ask has been solved already by the IDAPython project and I suggest you head over and look at their examples (here and here), especially this one.
The relevant idaapi
functions are:
idaapi.get_import_module_qty
idaapi.enum_import_names