Title: Scrapy, Xpath, extracting h3 content?
Tags: html;python-3.x;xpath;web-scraping;scrapy
Question: I need to extract everything after h3 class AIRFRAME /h3 but before h3 class ENGINES /h3:
What I need extracted:
&quot;Entry Into Service: December 2010
Total Time Since New: 3,580 Hours&quot; etc.
HTML code photo - not sure how to embed it directly instead of having a link
Below is what I've tried but it doesn't return anything. I'm new to Scrapy and programming in general so I would appreciate some help. I've tried searching through other posts and google in general without any luck.
input = response.xpath(&quot;//div[@class='large-6 cell selectorgadget_rejected']/h3/text()&quot;).extract()
output = []

Comment: Thanks. This was my first post so I'll keep that in mind for the future.

Comment: Do **never** include code as image. Always copy it as text in a `code` section, because otherwise an attempt could not be reproduced and would be worthless for SO.

Comment: HINT: Check if the value of the @class attribute contains a line-break.

Here is the accepted answer: The code that you are using is referencing another class that doesn't have the text you mentioned.
```input = response.xpath(&quot;//div[@class='large-6 cell selectorgadget_rejected']/h3/text()&quot;).extract()
```
The name of the class in the picture is ```large-6 cell selectorgadget_selected``` and not ```large-6 cell selectorgadget_rejected```
Also, if you use ```.../h3/text()``` you are going to scrape the text inside the H3 tag.
As I understand you want the text after the H3, between the ```<div&gt;```. So try something like this:
```input = response.xpath(&quot;//div[@class='large-6 cell selectorgadget_selected']/text()&quot;).extract()
```

Comment for this answer: Thank you. Using your code above as a reference (I made a slight change) I was able to get an output of the content after the `` tag. The code is: `response.xpath("//div[@class='large-6 cell']/text()").extract()` There are 4 different `` tags from which I need to get information, AIRFRAME being one of them. The 4 tags are part of the `large-6 cell` class and thus I get the results for all 4 in the same output. How would I change my code so that the output is only for AIRFRAME?
Comment for this answer: Hi @Arty, that's hard to answer without seeing the actual html. You can try something like this in the XPath: `//div[@class='large-6 cell']/h3[contains(text(), "AIRFRAME")]/parent181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16iv/text()`. It will only find the H3 that contains the text inside the quotes `" "` and will return to the parent `` for the text. - If my answer solved your issue, please accept it by clicking the checkmark.

Here is another answer: To complete @renatodvc's answer, you could add ```normalize-space``` function to ignore whitespace nodes.
```//div[@class='large-6 cell selectorgadget_selected']/text()[normalize-space()]
```
Or use the function directly on the element :
```normalize-space(//div[@class='large-6 cell selectorgadget_selected'])
```
Output :
```AIRFRAME &quot; Entry Into Service: December 2010&quot; &quot; Total Time Since New: 3,58@ Hours&quot; &quot; Total Landings Since New: 1,173&quot; &quot; (as of September 2019)&quot; &quot; Program Coverage: Enrolled on Smart Parts Plus&quot; &quot; Maintenance Tracking: CAMP &quot;
```
Then, to extract the values, you can use regex :
```import re
text = 'AIRFRAME &quot; Entry Into Service: December 2010&quot; &quot; Total Time Since New: 3,58@ Hours&quot; &quot; Total Landings Since New: 1,173&quot; &quot; (as of September 2019)&quot; &quot; Program Coverage: Enrolled on Smart Parts Plus&quot; &quot; Maintenance Tracking: CAMP &quot;'
data = [el.strip() for el in re.findall(':(.+?)\&quot;', text, re.IGNORECASE)]
print(data)
```
Output :
```['December 2010', '3,58@ Hours', '1,173', 'Enrolled on Smart Parts Plus', 'CAMP']
```

Comment for this answer: Your expression contains a typo. It should be : `response.xpath("//div[@class='large-6 cell selectorgadget_selected']/text()[normalize-space()]").get()`
Comment for this answer: Thanks! The `normalize-space` function doesn't seem to work. I tried the following code `response.xpath("//div[@class='large-6 cell']/text()")[normalize-space()].extract()` and got the following error `name 'normalize' is not defined`

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:07/07/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<html><python-3.x><xpath><web-scraping><scrapy>', 'Title': 'Scrapy, Xpath, extracting h3 content?', 'ViewCount': 389, 'id': 62780252, 'user_AboutMe': None, 'user_AccountId': 18441410.0, 'user_DisplayName': 'Arty', 'user_Reputation': 129.0, 'user_Views': 36.0, 'user_id': 13433955.0}}