简单的介绍下xpath和css的定位
理论知识就不罗列了
还是利用博客园的首页、直接附上代码:
这个是xpath
1 #!/usr/bin/env python 2 # -*- coding: utf_8 -*- 3 4 from learn_webdriver import Webdriver 5 from selenium import webdriver 6 from selenium.webdriver.common.action_chains import ActionChains 7 from time import sleep 8 9 browser_chrome = webdriver.Chrome(Webdriver.chrome())10 browser_chrome.get("http://www.cnblogs.com/")11 12 sleep(2)13 ActionChains(browser_chrome).move_to_element(browser_chrome.find_element_by_xpath(".//li[@id='cate_item_2']")).perform()14 # 鼠标悬停在左侧“编程语言”导航栏上15 browser_chrome.find_element_by_xpath(".//a[@href='/cate/python/']").click()16 sleep(2)17 browser_chrome.quit()
XPath 是一门在 XML 文档中查找信息的语言
使用的是函数是 find_element_by_xpath
这里总结了xpath的表达式:
表达式 | 说明 | 案例 |
节点名称 | 选取节点下所有子节点 | body body 下所有子节点 |
/ | 从根节点选取 | body/div body 下所有 div 节点 |
// | 匹配选择节点 不考虑位置 | //div 不考虑位置的 div 节点 |
. | 当前节点 | |
.. | 当前节点的父节点 | |
@ | 选取属性 | .//li[@id='cate_item_2'] li节点 且属性id=cate_item_2 |
下面是css
1 #!/usr/bin/env python 2 # -*- coding: utf_8 -*- 3 4 from learn_webdriver import Webdriver 5 from selenium import webdriver 6 from selenium.webdriver.common.action_chains import ActionChains 7 from time import sleep 8 9 browser_chrome = webdriver.Chrome(Webdriver.chrome())10 browser_chrome.get("http://www.cnblogs.com/")11 12 sleep(2)13 ActionChains(browser_chrome).move_to_element(browser_chrome.find_element_by_css_selector("li[id = 'cate_item_2']")).perform()14 # 鼠标悬停在左侧“编程语言”导航栏上15 browser_chrome.find_element_by_css_selector("a[href = '/cate/python/").click()16 sleep(2)17 browser_chrome.quit()
css更加灵活一些
css使用的函数是 find_element_by_css_selector

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.