我尝试使用urllib2跟踪url的重定向。在
>>> import urllib2
>>> page=urllib2.urlopen('http://acer.com')
>>> print page.geturl()
http://www.acer.com/worldwide/selection.html
>>>page=urllib2.urlopen('http://www.acer.com/worldwide/selection.html')
>>> print page.geturl()
http://www.acer.com/worldwide/selection.html
但是当我在浏览器中打开http://www.acer.com/worldwide/selection.html
时,它会重定向到http://us.acer.com/ac/en/US/content/home#_ga=1.216787925.232352975.1435019296
如何使用urllib检测这种重定向。在
get_url()
并不适用于所有重定向(例如JavaScript重定向)你想达到什么目的?在
以PhantomJS为后端的Selenium可能更适合这种情况。在
对于屏幕截图,您可以使用^{} ,它是Selenium Webdriver的一部分
使用
selenium
开始。我使用chromedriver作为浏览器:from selenium.webdriver import Chrome cr = Chrome() cr.get(url) cr.save_screenshot('IMAGE_NAME.png')
相关问题 更多 >
编程相关推荐