I would make a case for the former. I think it is WAY easier to find a publisher if you research the market FIRST. Because if you know that no publishers are accepting stories with animal characters in them, then you can avoid having spent a whole lot of time on writing something nobody will buy. So if you are wanting to write a romance novel. Look at what is out on the shelves. Go to the library and read a bunch of books in the type of genre you are interested in. This is to help you avoid putting out the same old thing that is already out there. You will be able to see where the market is over-saturated.
Then find a copy of the "Writer's Market." Look up the publishers in the genre you are interested in writing. Find their websites. The websites should tell you what each publisher is looking for. You can do this when finding an agent as well. Then, once you have a good idea of what publishers and agents are looking for, write away! You'll be secure in the knowledge that there actually IS a market for what you are writing, and you are not wasting valuable creative energy and writing time.