Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris committed Apr 3, 2021
1 parent aedac50 commit 29cb39e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
32 changes: 24 additions & 8 deletions docs/source_code/Response.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,31 @@ def re_first(self, regex, default=None, replace_entities=False):
response.re("<a.*?href='(.*?)'")
```

### 6. 定位混用
### 6. 支持BeautifulSoup

三种定位方式可混用,如:
默认的features为`html.parser`

```python
def bs4(self, features="html.parser"):
pass
```

例如获取标题:

```python
response.bs4().title
```


### 7. 定位混用

xpath、css两种定位方式可混用,如:

```
response.css("a").xpath("./@href").extract()
```

### 7. 取文本
### 8. 取文本

取文本有两种方式

Expand All @@ -115,27 +131,27 @@ response.extract()

如:网页源码`<a class='page-numbers'...` 会被处理成`<a class="page-numbers"`

### 8. 取json
### 9. 取json

```
response.json
```

### 9. 查看下载内容
### 10. 查看下载内容

```
response.open()
```

这个函数会打开浏览器,渲染下载内容,方便查看下载内容是否与数据源一致

### 10. 将普通response转为feapder.Response
### 11. 将普通response转为feapder.Response

```
response = feapder.Response(response)
```

### 11. 序列化与反序列化
### 12. 序列化与反序列化

序列化

Expand Down Expand Up @@ -181,7 +197,7 @@ feapder.Response写法如下
```
response.code="utf-8"
```
做了简化
做了简化,不过`response.enconding`也支持

### 3. 解码方式(二进制转字符串方式)

Expand Down
5 changes: 2 additions & 3 deletions feapder/network/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,8 @@ def selector(self):
self._cached_selector = Selector(self.text)
return self._cached_selector

@property
def bs4(self):
soup = BeautifulSoup(self.text, "html.parser")
def bs4(self, features="html.parser"):
soup = BeautifulSoup(self.text, features)
return soup

def extract(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/air-spider/test_air_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def download_midware(self, request):
return request

def parse(self, request, response):
print(response.bs4.title)
print(response.bs4().title)
print(response.xpath("//title").extract_first())


Expand Down

0 comments on commit 29cb39e

Please sign in to comment.