Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 使用Selenium获取响应代码的最佳方法?_Python_Selenium_Request - Fatal编程技术网

Python 使用Selenium获取响应代码的最佳方法?

Python 使用Selenium获取响应代码的最佳方法?,python,selenium,request,Python,Selenium,Request,我正在构建一个web爬虫程序,并刚刚将Selenium添加到爬虫程序中,但我意识到,如果不在Selenium之前使用请求,就无法获取http状态代码 我使用Selenium是因为我需要在页面完全加载后获取页面内容 所以现在我的爬虫正在这样做 1. Using request to get http status_code (Counts as 1 reqeust) 1.. Got response code (200,301,400) 2. Using Selenium to get page

我正在构建一个web爬虫程序,并刚刚将Selenium添加到爬虫程序中,但我意识到,如果不在Selenium之前使用请求,就无法获取http状态代码

我使用Selenium是因为我需要在页面完全加载后获取页面内容

所以现在我的爬虫正在这样做

1. Using request to get http status_code (Counts as 1 reqeust)
1.. Got response code (200,301,400)

2. Using Selenium to get page content (Counts as 1 reqeust)
2.. Got page content from Selenium

问题是,我正在使用2个请求来获取完整的页面内容,是否存在这样的情况,可能没有使用Selenium,在那里我可以获取页面和响应代码,但只能使用1个请求?

简单地说,从Selenium webdriver API获取状态代码目前是不可能的,并且永远不会添加到API中

我知道不可能单独从Selenium获取状态代码,但是不使用Selenium还有更好的方法吗?@user3502250最快最简单的方法是使用请求库,如果r.status_code==200:self.webdriver=webdriver.Chrome self.webdriver.geturl,则生成一个简单的条件r=requests.geturl这就是我今天所做的,但是请求调用是一个请求,webdriver.get是另一个请求,如果你知道我的意思,我只想总共调用一个请求调用:我在回答中告诉过你-不可能用selenium来检查这种状态,而且永远不会-检查我所附的链接我不想找一种没有selenium的方法来做这件事,我要的是另一种完全可以做到这一点的方法,它不需要selenium。所以答案对我没有帮助。