问题描述如下:
1.首先 通过 requests 提交 form 请求,登录成功后 保存 session
此时 可以通过selenium 用 登录之后的session 继续发送请求吗 ?因为想要实现自动回复消息功能,但是聊天窗口界面在别的 url中,而且 在聊天窗口界面需要通过 按enter键 或者 点击发送按钮发送消息
在这种情况下, selenium 和 requests 可以配合使用吗?谢谢各位了!
闭关修行中......
I have done similar functions, but I only used Selenium to do it. The core code is as follows:
def get_allgroupid(): driver = webdriver.PhantomJS() driver.get(address) driver.add_cookie({ 'name': 'Cookie', 'value':'p_uin=o ......此处省略若干字.....' }) driver.get(address) jsonstr= unicode(driver.find_element_by_xpath("html/body").text) driver.quit() groupid_list=re.findall('\d*\d{4,}',jsonstr) return groupid_list
I thought about it again, and the answer to the question raised by the questioner is yes. You can do this:
Use requests to submit a request and get the session after the request;
Use Selenium to add the session in step 1 to the driver
Use the driver to do what you want. At this time, the driver already contains the session. You try it and see if this idea works.
I have done similar functions, but I only used Selenium to do it. The core code is as follows:
I thought about it again, and the answer to the question raised by the questioner is yes. You can do this:
Use requests to submit a request and get the session after the request;
Use Selenium to add the session in step 1 to the driver
Use the driver to do what you want. At this time, the driver already contains the session.
You try it and see if this idea works.