这里是HTML代码:
Specific text 1
link1 inside specific text 1
link2 inside specific text 1
link3 inside specific text 1
Specific text 2
link1 inside specific text 2
link2 inside specific text 2
link3 inside specific text 2
link4 inside specific text 2
Specific text 3
link1 inside specific text 3
link2 inside specific text 3
links = root.xpath("//div[@id='someid']//a")
for link in links:
print link.attrib['href']它打印所有链接,而不考虑“特定文本x”,而我想要的东西如:
print "link under Specific text:"+specific+" link:"+link.attrib['href']请建议