In order to better handle the dynamic task allocation of UAV swarms, this paper first models the task allocation problem of UAV swarms. Then, improvements were made to the previous auction-based methods in terms of two aspects-the auction function and auction mechanism, and a two-stage task allocation method for UAV swarms based on an improved auction mechanism was proposed. When improving the auction function, an auction function with a parameter considering both UAVs and tasks was designed. By using machine learning to obtain the parameter, relatively stable experimental performance can be achieved. To further optimize the performance, a re-auction mechanism was proposed. Finally, by comparing with commonly used methods based on auction mechanisms, including the method of a linear combination of the MiniSum and MiniMax team objectives for task allocation and the other method, the feasibility of improving the auction function and auction mechanism was verified, and better experimental results were obtained.