Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
looyolo
scrapy
提交
bdea071a
S
scrapy
项目概览
looyolo
/
scrapy
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scrapy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bdea071a
编写于
4月 24, 2014
作者:
M
Mikhail Korobov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DOC selectors.rst cleanup
上级
5f188164
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
10 deletion
+10
-10
docs/topics/selectors.rst
docs/topics/selectors.rst
+10
-10
未找到文件。
docs/topics/selectors.rst
浏览文件 @
bdea071a
...
...
@@ -77,7 +77,7 @@ it's totally OK to use this shortcut when possible::
>>> response.selector.xpath('//span/text()').extract()
[u'good']
Using selectors
---------------
...
...
@@ -199,8 +199,8 @@ too. Here's an example::
u'
<a
href=
"image5.html"
>
Name: My image 5
<br><img
src=
"image5_thumb.jpg"
></a>
']
>>> for index, link in enumerate(links):
args = (index, link.xpath('@href').extract(), link.xpath('img/@src').extract())
print 'Link number %d points to url %s and image %s' % args
...
args = (index, link.xpath('@href').extract(), link.xpath('img/@src').extract())
...
print 'Link number %d points to url %s and image %s' % args
Link number 0 points to url [u'image1.html'] and image [u'image1_thumb.jpg']
Link number 1 points to url [u'image2.html'] and image [u'image2_thumb.jpg']
...
...
@@ -245,17 +245,17 @@ it actually extracts all ``<p>`` elements from the document, not only those
inside ``
<div>
`` elements::
>>> for p in divs.xpath('//p'): # this is wrong - gets all
<p>
from the whole document
>>>
print p.extract()
...
print p.extract()
This is the proper way to do it (note the dot prefixing the ``.//p`` XPath)::
>>> for p in divs.xpath('.//p'): # extracts all
<p>
inside
>>>
print p.extract()
...
print p.extract()
Another common case would be to extract all direct ``
<p>
`` children::
>>> for p in divs.xpath('p'):
>>>
print p.extract()
...
print p.extract()
For more details about relative XPaths see the `Location Paths`_ section in the
XPath specification.
...
...
@@ -375,7 +375,7 @@ with groups of itemscopes and corresponding itemprops::
... .//*[@itemscope]/*/@itemprop)''')
... print " properties:", props.extract()
... print
...
current scope: [u'http://schema.org/Product']
properties: [u'name', u'aggregateRating', u'offers', u'description', u'review', u'review']
...
...
@@ -453,7 +453,7 @@ Built-in Selectors reference
``query`` is a string containing the XPATH query to apply.
.. note::
For convenience this method can be called as ``response.xpath()``
.. method:: css(query)
...
...
@@ -466,7 +466,7 @@ Built-in Selectors reference
`cssselect`_ library and run ``.xpath()`` method.
.. note::
For convenience this method can be called as ``response.css()``
.. method:: extract()
...
...
@@ -560,7 +560,7 @@ a :class:`~scrapy.http.HtmlResponse` object like this::
3. Iterate over all ``
<p>
`` tags and print their class attribute::
for node in sel.xpath("//p"):
...
print node.xpath("@class").extract()
print node.xpath("@class").extract()
Selector examples on XML response
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录