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

标签 python-2.7 mechanize data-cleaning

我需要获取链接的最终 url。但是这个代码只给了我一个链接到它的商店

它返回给我链接: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

最佳答案

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

关于python-2.7 - 需要获得确切的重定向链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39717941/

相关文章:

python - Python 中是否有相当于 Unix 中 vfork 的工具?

python - 删除短语和括号并对数据框进行排序

python - 从数据框列中提取异常

r - 如何交换 R 中两列子集中的值?

Python静态变量生成器函数

Python 2.7 和 MySQL Ubuntu 安装 - ZipImportError

python - 如何匹配字符串中的确切单词?

Ruby Mechanize 不断重定向到原始登录页面

python - 无法按下按钮

python - 在 R 中重新创建 python Mechanize 脚本