网站更新内容:请访问: https://bigdata.ministep.cn/

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注释同上
posted @ 2022-01-27 14:51  ministep88  阅读(571)  评论(0编辑  收藏  举报
网站更新内容:请访问:https://bigdata.ministep.cn/