需要获得确切的重定向链接

时间:2016-09-27 06:54:10

标签: python-2.7 mechanize data-cleaning

我需要获取链接的最终网址。但是这段代码只给了我一个商店的链接

它返回了我的链接:http://www.amazon.in/electronics/b?ie=UTF8&node=976419031

但我需要的是:http://www.amazon.in/Samsung-G-550FY-On5-Pro-Gold/dp/B01FM7GGFI?tag=prdeskdetailmob-21&ascsubtag=desktop-mobile-15920-blank-27092016

import mechanize

br = mechanize.Browser()
br.open("https://priceraja.com/r/go2store.php?mpc=mobile--1178916--15920--deskdetail")
br.select_form(nr=0)
br.submit()
x=br.geturl()
print x

1 个答案:

答案 0 :(得分:0)

from selenium import webdriver
chrome_path = r"C:\Users\Bhanwar\Desktop\price raja mobile\working\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
link = "https://priceraja.com/r/go2store.php?mpc=mobile--1185105--15236--deskdetail"
driver.get(link)
while(link == driver.current_url):
  time.sleep(3)
redirected_url = driver.current_url
print redirected_url