Skip to main content
 首页 » 编程设计

python之python Mechanize 缓存功能是否与普通浏览器缓存功能相同

2025年05月04日12TianFang

在其文档中,它说“可以通过使用 Mechanize.OpenerDirector 来避免这种缓存行为”。此缓存是否影响同一页面的下一个请求?

请您参考如下方法:

在我看来,文档中提到的“缓存”是指可搜索的响应,而不是类似浏览器的缓存功能。例如:

total_nr_bytes = len(response.get_data()) 
assert len(response.read()) == total_nr_bytes 
assert len(response.read()) == 0  # we've already read the data 
response.seek(0) 
assert len(response.read()) == total_nr_bytes 

它会在您调用 python 对象中的 .read() 后缓存数据,如果您再次请求页面,不会缓存页面本身。

简答:不会,不会影响同一页面的下一次请求