#coding=utf-8
import requests
import json
from selenium import webdriver
class requests_webdriver:
def init(self):
self.driver = self.chrome_driver()
def chrome_driver(self):
url = ‘http://127.0.0.1:4444/wd/hub/session’
#json.dumps 把json转换成字符串
data = json.dumps({
‘desiredCapabilities’:{
‘browserName’:‘chrome’
}
})
Response = requests.post(url,data).json()
session = Response[‘sessionId’]
driver = url + session
print(session)
return driver
def get_url(self,url):
base_url = self.driver+'/url'
data = json.dumps({
"url":url
})
requests.post(base_url,data)
if name == ‘main’:
request_driver = requests_webdriver()
request_driver.get_url(‘http://www.baidu.com’)