(self)
| 144 | assert resp.jmespath("content").jmespath("name.age").get() == "18" |
| 145 | |
| 146 | def test_html_has_json(self) -> None: |
| 147 | body = """ |
| 148 | <div> |
| 149 | <h1>Information</h1> |
| 150 | <content> |
| 151 | { |
| 152 | "user": [ |
| 153 | { |
| 154 | "name": "A", |
| 155 | "age": 18 |
| 156 | }, |
| 157 | { |
| 158 | "name": "B", |
| 159 | "age": 32 |
| 160 | }, |
| 161 | { |
| 162 | "name": "C", |
| 163 | "age": 22 |
| 164 | }, |
| 165 | { |
| 166 | "name": "D", |
| 167 | "age": 25 |
| 168 | } |
| 169 | ], |
| 170 | "total": 4, |
| 171 | "status": "ok" |
| 172 | } |
| 173 | </content> |
| 174 | </div> |
| 175 | """ |
| 176 | resp = TextResponse(url="http://example.com", body=body, encoding="utf-8") |
| 177 | assert resp.xpath("//div/content/text()").jmespath("user[*].name").getall() == [ |
| 178 | "A", |
| 179 | "B", |
| 180 | "C", |
| 181 | "D", |
| 182 | ] |
| 183 | assert resp.xpath("//div/content").jmespath("user[*].name").getall() == [ |
| 184 | "A", |
| 185 | "B", |
| 186 | "C", |
| 187 | "D", |
| 188 | ] |
| 189 | assert resp.xpath("//div/content").jmespath("total").get() == "4" |
| 190 | |
| 191 | def test_jmestpath_with_re(self) -> None: |
| 192 | body = """ |
nothing calls this directly
no test coverage detected