我正在尝试在 scrapy 中获取最终重定向的 URL。例如,如果锚标记具有特定格式:
<a href="http://www.example.com/index.php" class="FOO_X_Y_Z" />
然后我需要获取 URL 重定向到的 URL(如果是,如果是 200 则 OK)。例如,我得到适当的锚标签,如下所示:
def parse (self, response)
hxs = HtmlXPathSelector (response);
anchors = hxs.select("//a[@class='FOO_X_Y_Z']/@href");
// Lets assume anchor contains the actual link (http://...)
for anchor in anchors:
final_url = get_final_url (anchor); // << I would need something like this
// Save final_url
因此,如果我访问了http://www.example.com/index.php
,那将通过 10 次重定向发送给我,最后它会停止http://www.example.com/final.php
- 这就是我需要get_final_url()
返回的内容。
我想破解我的解决方案,但我在这里问scrapy是否已经提供了一个?