You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过PowerShell每次获取动态PHP网页的新内容?

解决方法

问题根源是请求被缓存,服务器返回了旧内容而非重新生成的随机文本,可通过以下两种方式解决:

方法一:禁用请求缓存

在Invoke-WebRequest中添加请求头,强制服务器跳过缓存,返回新生成的内容:

$headers = @{
    "Cache-Control" = "no-cache, no-store, must-revalidate"
    "Pragma" = "no-cache"
    "Expires" = "0"
}
$page = Invoke-WebRequest -Uri https://cicero.blazni.cz/lipsum.php -Headers $headers
$reading = $page.ParsedHtml.getElementById("rightcol").firstChild.innerHTML
$reading

方法二:添加随机查询参数

每次请求时在URL末尾附加随机生成的参数,让服务器识别为全新请求,触发PHP重新生成随机文本:

$rand = Get-Random
$page = Invoke-WebRequest -Uri "https://cicero.blazni.cz/lipsum.php?rand=$rand"
$reading = $page.ParsedHtml.getElementById("rightcol").firstChild.innerHTML
$reading

两种方法都能保证每次运行代码时,服务器都会生成新的随机文本,返回不同结果。

内容的提问来源于stack exchange,提问作者Lucie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 14:40:34