在学习scrapy中用xpath提取网页内容时,有时要先提取出一整个行标签内容,再从行标签里寻找目标内容.出现一个错误. 错误代码: def parse(self, response): sel = scrapy.Selector(response) sel_li = sel.xpath('/html/body/div[2]/div[5]/div[1]/ul/li') for i in sel_li: print(i.xpath('//h5/a/text()').extract()[0]) 结果
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <t