update for colab chrome
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=options)
import re
import time
https://www.796t.com/article.php?id=101939
https://www.cnblogs.com/yoyoketang/p/14124336.html
https://www.i4k.xyz/article/weixin_49167820/117437965
https://blog.csdn.net/HHG20171226/article/details/102623940
input = driver.find_element(By.XPATH,'query_ticket') or driver.find_element(By.TAG_NAME,'query_ticket') or driver.find_element(By.NAME,'query_ticket') or driver.find_element(By.CLASS_NAME,'query_ticket') or driver.find_element(By.CSS_SELECTOR,'query_ticket')
input.send_keys("13728556386")
btn = driver.find_element(By.ID,'query_ticket') == driver.find_element_by_id('query_ticket')
driver.execute_script('arguments[0].click()',btn)
#or driver.execute_script('xxx_copy from js path_xxx.click()',btn)
button = driver.wait.until(EC.presence_of_element_located(
(By.XPATH, "//div[@id='pagination-element']/nav[1]/span[3]/button[1]/span[1]/i[1]")
))
driver.execute_script("arguments[0].click();", button)
driver.execute_script("window.scrollTo(0, Y)") Y is the vertical position where you wanna move to
WebDriverWait(driver,10).until(expected_conditions.presence_o f_element_located((By.ID,'xxxx')))
driver.execute_script('''document.querySelector("button[type='submit']").click();''')
wd_elements(By.CSS_SELECTOR, "#data-util-col > section:nth-child(6) > table > tbody > tr:nth-child(2) > td.Va\(t\).Fz\(14px\).Whs\(nw\).Py\(6px\).Ta\(start\).Start\(0\).Pend\(10px\) > a").click()
#wd.find_element(By.ID, "id")
e.g.
elem = driver.find_element_by_css_selector("button[type='submit']")
driver.execute_script("arguments[0].click()", elem)
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR , '.flt-subhead1.gws-flights-results__price.gws-flights-results__cheapest-price span + jsl')))
Chrome browser example:
<link rel="multiply" type="service/math" src="path/to/service">
<link rel="substract" type="service/math" src="path/to/service">
...
trying to use querySelectorAll to retrieve all link elements with a type service/... specified
e.g. ... document.querySelectorAll( 'link' ) #return a list
document.querySelector( 'link' ) #return an element
document.querySelector( 'link' ).click() #click an element button
document.querySelector( 'link' ).value='xxxxx' #input sth. into an input box
document.querySelectorAll( 'link' ).innerText #get the pure text of HTML
document.querySelectorAll( 'link' ).innerHTML #get the corresponding HTML code with text
document.getElementById
document.getElementsByName
document.getElementsByTagName
document.getElementsByClassName
. <-for class selector
# <-for id selector
[... document.querySelectorAll( 'link' )] #three dots before aims to return a normal list
Filtering the ones with type service/.* ?
You can use a substring matching attribute selectors : link[type^=service]
"Nodes of type link with an attribute type starting with the letter "service" -just like a regular expression
g. document.querySelectorAll( '[ng-controller^="' + <controller name> + '"' )
python selenium
driver.execute_script("""return document.getElementById('kw').value""")
switch to the iframe window
driver.switch_to.frame(driver.find_element_by_css_selector(css_selector))
switch back to the main window
driver.switch_to.default_content()