如何检索 window.location 中给出的重定向 url

How to retrieve redirect url given in window.location

我正在尝试使用 Python 制作爬虫。我正在使用 beautifulsoup 和请求库,并且需要给定网站的一组 URL。但是,在某个部分,有重定向,当我打印 response.text 即页面内容时,我得到以下行

<script>
<!--
window.location = "redirect_URL/index.php"
-->
</script>

如何检索此 url 以便我抓取此 url

正则表达式如何

您只需检查 response.text 重定向发生 (python):

regex= /window\.location\s*=\s*\"([^"]+)\"/
var occurance = regex.exec(responce.text)
if (occurance[1]) 
    print occurance[1];     

参见the demo