xpath
F12 Sources (源代码)里面看,就是页面源代码
xpath(xml, html) 标签格式 刷选标签里面的属性,里面的内容
from lxml import etree
tree = etree.HTML(page_source)
src = tree.xpath("//iframe/@src")[0] # xpath 默认取到的东西是个列表 所以加个[0]
#./td 是拿到td标签,我们要的是标签里的内容,所以是./td/text()
# //a[contains(@href, '/song?id')]/@href 这个方法适合拿到所有的ids
# //a 拿到所有的a标签 contains 内容 属性前面加@ [contains(@href, '/song?id')] 拿到内容为 有属性href, 且有'/song?id' 的所有a标签 这里'/song?id' 可以不用写全 /@href 拿到a里面的属性id号
ids = dom.xpath("//a[contains(@href, '/song?id')]/@href")

浙公网安备 33010602011771号