A numerical investigation on the power extraction of a pitching-motion-activated flapping foil near solid walls is performed by using an immersed boundary-lattice Boltzmann method in this study. The flapping motions of the foil include a forced pitching component and an induced plunging component. The foil is placed either near a solid wall or between two parallel plane walls. Compared to previous work on the flapping foil for power extraction, the effect of the walls is first considered in this work. At a Reynolds number of 1100 and with the position of the foil pitching axis at third chord, the influences of the mechanical parameters (such as damping coefficient and spring constant) of the foil, the amplitude and frequency of the pitching motion and the clearance between the foil pitching axis and the wall on the power extraction performance of the flapping foil are systematically evaluated. Compared to the situation of free stream, the power extraction performance of the foil near the wall is improved. For given amplitude and frequency, as the clearance decreases the net power extraction efficiency improves. Moreover, as the foil is placed near one wall, there is a transverse shift to the plunging motion that consequently weakens the improvement of net power extraction efficiency. In contrast, the shift can be significantly eliminated as the foil is placed between two walls, which can further improve the net power extraction efficiency. In addition, it is found that the efficiency improvement is essentially from the increased power extraction, which is due to the generation of high lift force.