Source: XPath css examples

← Rendered

markdown source:

---
description: Примеры Xpath и CSS выражений для извлечения данных из html
tags: crawlers python
title: XPath css examples
---
## How to get html elements with multiple css classes

```shell
//div[contains(@class, 'class1') and contains(@class, 'class2')]
```

more [on stack-overflow](https://stackoverflow.com/questions/3881044/how-to-get-html-elements-with-multiple-css-classes)

## XPath expression for selecting all text in a given node, and the text of its chldren

```shell
string(//div[@id='theNode'])

# or to reduce unwanted whitespace that might appear due
# to newlines and indenting in the source document
normalize-space(//div[@id='theNode'])

# if theNode was the context node, you could use this instead
# normalize-space()
```

[ссылка](https://stackoverflow.com/a/10424209/15966204)

## Using XPATH to select two different attributes

```shell
//ATHLETES/ATHLETE[RESULTS/RESULT/@resultid = '1673']/@key |
//ATHLETES/ATHLETE/RESULTS/RESULT[@resultid = '1673']/@time
```

## How to use not contains() in XPath?

```shell
//production[not(contains(category,'Business'))]
```

## XPath with multiple conditions

```shell
/category[@name='Sport' and author/text()[1]='James Small']
```

[источник](https://stackoverflow.com/questions/10247978/xpath-with-multiple-conditions)

```shell
//ul[@class='featureList' and ./li[contains(.,'Model')]]
```

[источник](https://stackoverflow.com/questions/1064968/how-to-use-xpath-contains-here)

Еще ссылки:

- [[xpath]]
- [[css-selectors]]
- [[crawlers]]


[xpath]: xpath "XPath в scrapy"
[css-selectors]: css-selectors "Css-selectors"
[crawlers]: ../lists/crawlers "Crawlers"