Currently, unmanned aerial vehicle (UAV) provides the possibility of comprehensive coverage and multi-dimensional visualization of pipeline monitoring. Encouraged by industry policy, research on UAV path planning in pipeline network inspection has emerged. The difficulties of this issue lie in strict operational requirements, variable flight missions, as well as unified optimization for UAV deployment and real-time path planning. Meanwhile, the intricate structure and large scale of the pipeline network further complicate this issue. At present, there is still room to improve the practicality and applicability of the mathematical model and solution strategy. Aiming at this problem, this paper proposes a novel two-stage optimization approach for UAV path planning in pipeline network inspection. The first stage is conventional pre-flight planning, where the requirement for optimality is higher than calculation time. Therefore, a mixed integer linear programming (MILP) model is established and solved by the commercial solver to obtain the optimal UAV number, take-off location and detailed flight path. The second stage is re-planning during the flight, taking into account frequent pipeline accidents (e.g. leaks and cracks). In this stage, the flight path must be timely rescheduled to identify specific hazardous locations. Thus, the requirement for calculation time is higher than optimality and the genetic algorithm is used for solution to satisfy the timeliness of decision-making. Finally, the proposed method is applied to the UAV inspection of a branched oil and gas transmission pipeline network with 36 nodes and the results are analyzed in detail in terms of computational performance. In the first stage, compared to manpower inspection, the total cost and time of UAV inspection is decreased by 54% and 56% respectively. In the second stage, it takes less than 1 minute to obtain a suboptimal solution, verifying the applicability and superiority of the method.