Skip to content

Commit ecf07ee

Browse files
committed
完善response文档
1 parent d539ce6 commit ecf07ee

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

docs/source_code/Response.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,39 @@ response.open()
145145

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

148-
### 11. 将普通response转为feapder.Response
148+
### 11. 更新response.text的值
149+
150+
```
151+
response.text = ""
152+
```
153+
常用于浏览器渲染模式,如页面有变化,可以取最新的页面内容更新到response.text里,然后使用response的选择器提取内容
154+
155+
### 12. 将普通response转为feapder.Response
149156

150157
```
151158
response = feapder.Response(response)
152159
```
153160

154-
### 12. 序列化与反序列化
161+
### 13. 将源码转为feapder.Response
162+
163+
```
164+
response = feapder.Response.from_text(text=html, url="", cookies={}, headers={})
165+
```
166+
167+
url是网页的地址,用来将html里的链接转为绝对链接,若不提供,则无法转换
168+
169+
示例:
170+
```
171+
import feapder
172+
173+
html = "<a href='/666'>hello word</a>"
174+
response = feapder.Response.from_text(text=html, url="https://www.feapder.com", cookies={}, headers={})
175+
print(response.xpath("//a/@href").extract_first())
176+
177+
输出:https://www.feapder.com/666
178+
```
179+
180+
### 14. 序列化与反序列化
155181

156182
序列化
157183

@@ -160,6 +186,7 @@ response = feapder.Response(response)
160186
反序列化
161187

162188
feapder.Response.from_dict(response_dict)
189+
163190

164191
### 其他
165192

0 commit comments

Comments
 (0)