Using Scrapy 0.24 Selectors, I want to extract the paragraph content including other element's content (in the following exemple, it'd be the anchor <a>
. How can I achieve that?
The Code
>>> from scrapy import Selector
>>> html = """
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<p>Hello, can I get this paragraph content without this <a href="http://google.com">Google link</a>?
</div>
</body>
</html>
"""
>>> sel = Selector(text=html, type="html")
>>> sel.xpath('//p/text()').extract()
[u'Hello, can I get this paragraph content with this ', u'?']
Output
[u'Hello, can I get this paragraph content with this ', u'?']
Expected output
[u'Hello, can I get this paragraph content with this Google link?']