The prediction of traffic flow is of great significance in the traffic field. However, because of the high uncertainty and complexity of traffic data, it is challenging that doing traffic flow prediction. Most of the existing methods have achieved good results in traffic flow prediction, but are not accurate enough to capture the dynamic temporal and spatial relationship of data by using the structural information of traffic flow. In this study, we propose a traffic flow prediction method with temporal attention mechanism and spatial attention mechanism based on neural architecture search (TS-NAS). Firstly, based on temporal and spatial attention mechanisms, we design a new attention mechanism. Secondly, we define a novel model to learn temporal flow and space flow in traffic network. Finally, the proposed method uses different modules about time, space and convolution and neural architecture search to be used for optimizing the model. We use two datasets to test the method. Experimental results show that the performance of the method is better than that of the existing method.