pyquery Of CSS Selectors are used to specify CSS Code , And pass CSS Code selection HTML The corresponding node in the document . Create a CSS The selector needs to create a PyQuery object ,PyQuery Class constructor needs to pass in a HTML file ( Can be a string 、URL Or document form ). because PyQuery Class overloads the function call operator ( Realized __call__ function ), So you can use the following code PyQuery Class .
from pyquery import PyQuery as pq
doc = pq(html)
# because PyQuery Class overloads the function call operator , So you can use... Like calling a function PyQuery Example , The function parameter is CSS Code
result = doc('#button1')
The following example uses PyQuery Object parses the string form of HTML Code and the homepage of Jingdong Mall HTML Code , And pass CSS The selector extracts a string HTML Node information in the code , And the text of the navigation bar link on the home page of Jingdong Mall .
The style of Jingdong Mall navigation bar is shown in the figure 1 Shown . What we want to extract is this line of text , Such as “ seckill ”、“ Coupon ” etc. .