scrapy解析html返回response
将response保存到本地调试
filePath = path + "hanglingdao" + str(number)+'.html'
print("filePath",filePath)
with open(filePath, 'w') as doc:
doc.write(response.text)
读取本地html内容
file = "htmlhanglingdao128728.html"
with open(file, "r", encoding='utf-8') as f:
html= f.read()
from scrapy.selector import Selector
from scrapy.http import HtmlResponse
response= HtmlResponse(url='http://www.example.com',body=html,encoding='utf8')
print(response.xpath('/html/head/title/text()')) # z注释同上