-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can not get blank text in td tag. #62
Comments
XPath's data model does not consider "blank text" as text nodes:
So the output of parsel seems correct to me. (And I get the same results with http://codebeautify.org/Xpath-Tester for example.) What you could do is to loop on
|
Python3.6.7
Error: |
Please, instead of hijacking an unrelated Scrapy issue, ask your question in StackOverflow. It is an easy question, I bet you will get a prompt answer there. |
@pc10201 >>> s.xpath("//tbody/tr//td").xpath("normalize-space()").getall()
['000-643', 'IBM', '', '45'] Full code from parsel import Selector
html = """
<table class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th>#</th>
<th>code</th>
<th>vendor</th>
<th>name</th>
<th>num</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1750</th>
<td><a href="/exam/000-643">000-643</a></td>
<td>IBM</td>
<td></td>
<td>45</td>
</tr>
</tbody>
</table>
"""
s = Selector(text=html)
with_text = s.xpath("//tbody/tr//td//text()").getall()
with_normalize_space = s.xpath("//tbody/tr//td").xpath("normalize-space()").getall()
print(with_text, with_normalize_space) Output
I'm commenting on this old issue because I've faced it today. |
output
The text was updated successfully, but these errors were encountered: