这是我提出的上一个问题的后续跟进。我在Facebook广告中编码了URL,我希望我的python程序获取使用javascript重定向到的最终URL。因为它使用javascript,正常的urllib2 / mechanize跟踪重定向的方法不起作用,我对于解决这个问题的下一步应该有点迷失,因为我对python很新。
原始网址中的HTML(在普通浏览器中重定向时)如下:
<html><body><script type="text/javascript">/* <![CDATA[ */document.location.replace("http:\/\/www.facebook.com\/ajax\/emu\/r.php?u=AQIp41Zwc9sY8Ww3nVilFEp65wGTqRy0HFkoPknfO0PMmv8ReqE5hUWspFXZpc5voUSBpsALvKAELk_nKIxnbfo3exlOLjD6e37JqMqTu8_mhtsdYHW1D2TBW9ja5tz8RevsT2C6ioKSVImbTA1aCAvZfSOum2_utZe-FQZQy7hUJvIxgwUlgxCBO00MyFnChMBk3srXc3FlZZWGJh5bLXtX0PlCaGfNwzsS1pHBsI_aEZeuWvrqh2x264WxQloG15QKkYg7zfvyoOTByNRR686THDx9KyV52eRAkME3z2pM76sYr0NjOkBXJaMQuc0qvVuz5OF3mhaPGW3cjcCh9K2j_he7GC-cyDtcdMevIT0qSH4sxCM9KxqnsRPTIHBAXEDPQysAdadyfs3p3Q3rgg1atUzGzdkCshyqaoDhHFhBreUYJ2TUWm7DQ7cpJ9vYDQ2qEvaZxUiz67RKzmIPqi7Zzidzo6t19yMwGGSIcdxg87xZZ5qZ8NGV8VdXXvQ-AxA-xOt4fiWJmVJUnaAl8m46ATo0K3prACIJN8FILMBYPWlDW7tmOGIvcT8CA-lwXysrVvkZjMJxhzknmw0hZ8gt9E1RVmeCNKb8xmGp1acXGsy49OZlXqk0wiLIFY04gCs8vo3FmHHEGQUX4ZECeFCbAdVUBDzHwRPyMtwVZ4dVoBwws6oiXVtAYDe4KCVGRQe_-axOVxO_zhWH8J4q89E_hWVJ0_dlhkhSotyzeh3flKXfzgKr8VDs07ZIl8v9XTvIZD2PRUxmBT9IRxzCUv9UC0s4JMG7-TnKoANh133TrwpiDx-QWT_9rRAoM4oupazJxy4tkudUICCG3ancGpGdP_GcWAGkRlc5p25kBi4eiqJgO-KIxNVg5YkEINh5NlblQY16pGbqtkOmYmxQedahuPkykAexOsYtuaZRv4k3DGjLR-uBUhHkpUz0SS3fJwbVcuCgq5Aup27-bjR9bgFnHDMLWF0EbNBHB_0d0oppzAh93x7yVCvt-acoNS9KBSKNNnRUn3H0ZsDd0HBOT-oI_aZKfiumD2NYjgwXJWRPb54_85ju89ZeD9KUBwCqfPFc0Wr6TOtAUxrv-7nr_Bn3MUkGI5zWmnA32QOMHzay1CtLZ5FRzcwXEXIVfrJeeVvm3x-4TCxQ4FrCa591VAj3B_hCYdv6IzERGkBm6K3LKd1EZL_dATRRegKjNavUChzI2_rLAyrMduLniaD7H1bwktNq78GXAT3taId-FVysw8Il7OamCKldlWtbcuGL2KHfNHVBWigi2AuqdyagRPmIqLcIe7TkdiZ4e9n5bm9O_M9MuX0OV0NseOMbmUFvQMZSAjXE_hrwJjanlHVUdNiL5psdujE_RVM4uwNhb9t-VhCJw70HhUG-Xqc0O09cfemJfGnoFRRPmFkTuX_dg1Fzx_ARCBnl6GBjbMdiLle3eduaK7ldN1VU9BstZjKNqWn691qxaJGdzCVaYo3w_5SMQfC9OfceWtrMQ-UZ3cnfG2lJ_w6yEDa-1b6rZ9UQRnA");/* ]]> */</script><script type="text/javascript">/* <![CDATA[ */setTimeout("(new Image()).src='/laudit.php?r=JS&u=http%3A%2F%2Fwww.facebook.com%2Fajax%2Femu%2Fr.php%3Fu%3DAQIp41Zwc9sY8Ww3nVilFEp65wGTqRy0HFkoPknfO0PMmv8ReqE5hUWspFXZpc5voUSBpsALvKAELk_nKIxnbfo3exlOLjD6e37JqMqTu8_mhtsdYHW1D2TBW9ja5tz8RevsT2C6ioKSVImbTA1aCAvZfSOum2_utZe-FQZQy7hUJvIxgwUlgxCBO00MyFnChMBk3srXc3FlZZWGJh5bLXtX0PlCaGfNwzsS1pHBsI_aEZeuWvrqh2x264WxQloG15QKkYg7zfvyoOTByNRR686THDx9KyV52eRAkME3z2p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M4uwNhb9t-VhCJw70HhUG-Xqc0O09cfemJfGnoFRRPmFkTuX_dg1Fzx_ARCBnl6GBjbMdiLle3eduaK7ldN1VU9BstZjKNqWn691qxaJGdzCVaYo3w_5SMQfC9OfceWtrMQ-UZ3cnfG2lJ_w6yEDa-1b6rZ9UQRnA';",5000);/* ]]> */</script></body></html>
我很抱歉我发布的方式,但我的问题是,重定向链接在某处吗?我已经尝试了一些不同的方法来复制HTML中的链接,但没有运气。任何帮助将不胜感激!
答案 0 :(得分:0)
document.location.replace()
是您使用JavaScript执行重定向的方式。如果您解析该方法调用中的URL,则可以在代码中手动关注该URL。