from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC4
from selenium.webdriver.support.wait import WebDriverWait
browser=webdriver.Chrome()
try:
browser.get('https://www.baidu.com')
input=browser.find_element_by_id('kw')
input.send_keys('Python')
input.send_keys(Keys.ENTER)
wait=WebDriverWait(browser,10)
wait.until(EC4.presence_of_element_located((By.ID,'content_left')))
print(browser.current_url)
print(browser.get_cookie())
print(browser.page_source)
finally:
browser.close()
from selenium import webdriver
browser=webdriver.Chrome()
browser=webdriver.Firefox()
browser=webdriver.Edge()
browser=webdriver.PhantomJS()
browser=webdriver.Safari()
from selenium import webdriver
browser=webdriver.Chrome()
browser.get('https://www.taobao.com')
print(browser.page_source)
browser.close()
from selenium import webdriver
from selenium.webdriver import ActionChains
browser=webdriver.Chrome()
url='http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
browser.get(url)
browser.switch_to_frame('iframeResult')
#选中要拖拽的节点和目标节点
source=browser.find_element_by_css_selector('#draggable')
target=browser.find_element_by_css_selector('#droppable')
声明ActionChains对象
actions=ActionChains(browser)
actions.drag_and_drop(source,target)
actions.perform()
#执行JavaScript对象
browser.execute_script('window.scrollTo(0,document.body.scrollHeight')
browser.execute_script('alert("To Bottom")')
#获取节点信息
logo=browser.find_element_by_class_name('zhihuLogolink')
#获取属性
print(logo.get_attribute('class'))
#获取文本值
input=browser.find_element_by_class_name('zu-top-add-question')
print(input.text)
#获取id,位置,标签名和大小
print(input.id)
print(input.location)
print(input.tag_name)
print(input.size)
browser.switch_to_frame('iframeResult')
try:
logo=browser.find_element_by_class_name('logo')
except NoSuchAttributeException:
print('NO LOGO')
browser.switch_to.parent_frame()
logo=browser.find_element_by_class_name('logo')
#隐式等待
from selenium import webdriver
browser=webdriver.Chrome()
browser.implicitly_wait(10)
browser.get('https://www.zhihu.com/explore')
#显示等待
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser=webdriver.Chrome()
browser.get('https://www.taobao.com/')
wait=WebDriverWait(browser,10)
input=wait.until(EC.presence_of_element_located((By.ID,'q')))
#等待条件
button=wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'.btn-search')))
print(input,button)
browser.back()
time.sleep(1)
browser.forward()
print(browser.get_cookies())
browser.add_cookie({
'name':'name','domain':'www.zhihu.com','value':'germey'})
print(browser.get_cookies())
browser.delete_all_cookies()
转载: link.
local title=splash:evaljs("document.title")
function main(splash,args)
local snapshots={
}
local timer=splash:call_later(function()
snapshots["a"]=splash:png()
splash:wait(1.0)
snapshots["b"]=splash:png()
end,0.2)
splash:go("https://www.taobao.com")
splash:wait(3.0)
return snapshots
end
import requests
url='http://localhost:8050/render.html?url=https://www.baidu.com&wait=5'#wait设置时间
response=requests.get(url)
print(response.text)
获取网页截图
实现与lua脚本的对接