Aspect Sentiment Triple Extraction (ASTE), a subtask of fine-grained sentiment analysis, aims to extract aspect terms, opinion terms, and their corresponding sentiment polarities from sentences. Previous methods often enumerated all possible spans of aspects and opinions as candidate spans that contain many invalid and irrelevant spans. This made the model training and prediction more difficult due to noised spans, leading to poor performance. To address this issue, we first propose a novel span-level approach that explicitly considers prior grammatical knowledge to generate possible candidate spans by part-of-speech filtering. In this way, our approach can make the model easier to be trained and achieve higher performance at the test stage. Besides, the quality of span-level representation of aspects and opinions is crucial for predicting their sentiment relation. To build a high-quality span-level representation of aspects and opinions, we first incorporate the contextual embedding of the entire sequence into span-level representations. Then, we introduce an auxiliary loss based on contrastive learning to make a more compact representation of the same polarities. Experimental evaluations on the 14Lap, 14Res, 15Res, and 16Res datasets demonstrate the effectiveness of our model, achieving state-of-the-art performance in span-based triplet extraction.