Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python不带response.history的反排序URL_Python - Fatal编程技术网

Python不带response.history的反排序URL

Python不带response.history的反排序URL,python,Python,我正在使用此代码取消对所有URL的排序,它可以正常工作,但无法在此特定的URL上工作“”-->URL包含aff链接 response = requests.get(url, timeout=15) if response.history: url_new = response.url 它根本找不到最终的url。结果应该是您看到的问题是重定向是通过Javascript执行的,而不是常规的HTTP重定向;此外,为了接收JS代码,您需要更改您的用户代理: 重新导入

我正在使用此代码取消对所有URL的排序,它可以正常工作,但无法在此特定的URL上工作“”-->URL包含aff链接

    response = requests.get(url, timeout=15)

    if response.history:
        url_new = response.url

它根本找不到最终的url。结果应该是

您看到的问题是重定向是通过Javascript执行的,而不是常规的HTTP重定向;此外,为了接收JS代码,您需要更改您的用户代理:

重新导入
导入请求
url=”https://www.shareasale-analytics.com/u.cfm?d=654202&m=52031&u=1363577&shrsl_analytics_sscid=41k4%5F9si0z&shrsl_analytics_sstid=41k4%5F9si0z"
headers={“用户代理”:“Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,像Gecko)Chrome/81.0.4044.122 Safari/537.36”}
response=requests.get(url,headers=headers)
如果响应.history:
url\u new=response.url
其他:
matches=re.findall(“window.location.replace\('(.'')\”,response.content.decode(),re.DOTALL)
如果匹配:
匹配=匹配[0]
url\u new=match.strip().replace(“\\”,“”)

之后,只需使用简单的正则表达式检索新URL。

您看到的问题是重定向是通过Javascript执行的,而不是通过常规的HTTP重定向;此外,为了接收JS代码,您需要更改您的用户代理:

重新导入
导入请求
url=”https://www.shareasale-analytics.com/u.cfm?d=654202&m=52031&u=1363577&shrsl_analytics_sscid=41k4%5F9si0z&shrsl_analytics_sstid=41k4%5F9si0z"
headers={“用户代理”:“Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,像Gecko)Chrome/81.0.4044.122 Safari/537.36”}
response=requests.get(url,headers=headers)
如果响应.history:
url\u new=response.url
其他:
matches=re.findall(“window.location.replace\('(.'')\”,response.content.decode(),re.DOTALL)
如果匹配:
匹配=匹配[0]
url\u new=match.strip().replace(“\\”,“”)

之后,只需使用一个简单的正则表达式检索新的URL。

这个特定URL的重定向由JS完成。这在使用浏览器时效果很好,python请求模块无法遵循这些重定向

我用邮递员一开始就发现了这一点。以下是我执行的步骤-

  • 使用浏览器(firefox)验证重定向是否有效。->成功了
  • 使用邮递员查看实际响应。这是邮递员收到的-
  • 
    window.location.replace('https:\/\/www.gearbest.com\/other novely lights\/pp\u 009234504925.html?wid=1433363&sscid=41k4\u 9si0z&utm\u source=shareasale&utm\u medium=shareasale&utm\u campaign=shareasasasale&sascid=41k4\u 9si0z&userID=1363577'))
    
    我删去了回复中的空白。 所以很明显,JS正在进一步重定向

    要使其工作,您需要执行2个步骤-

  • 更新标题中的用户代理,以便响应包含包含有关JS重定向信息的html
  • 你自己跟着重定向
    希望,这有帮助

    此特定URL的重定向由JS完成。这在使用浏览器时效果很好,python请求模块无法遵循这些重定向

    我用邮递员一开始就发现了这一点。以下是我执行的步骤-

  • 使用浏览器(firefox)验证重定向是否有效。->成功了
  • 使用邮递员查看实际响应。这是邮递员收到的-
  • 
    window.location.replace('https:\/\/www.gearbest.com\/other novely lights\/pp\u 009234504925.html?wid=1433363&sscid=41k4\u 9si0z&utm\u source=shareasale&utm\u medium=shareasale&utm\u campaign=shareasasasale&sascid=41k4\u 9si0z&userID=1363577'))
    
    我删去了回复中的空白。 所以很明显,JS正在进一步重定向

    要使其工作,您需要执行2个步骤-

  • 更新标题中的用户代理,以便响应包含包含有关JS重定向信息的html
  • 你自己跟着重定向 希望,这有帮助

    <head></head>
    
    <body>
    
    
      <script LANGUAGE="JavaScript1.2">
          window.location.replace('https:\/\/www.gearbest.com\/other-novelty-lights\/pp_009234504925.html?wid=1433363&sscid=41k4_9si0z&utm_source=shareasale&utm_medium=shareasale&utm_campaign=shareasale&sascid=41k4_9si0z&userID=1363577')
      </script>
    
    
    </body>
    
    </html>