Toapi give you the ability to make every web site provides APIs.
text
$ pip install toapi
create app.py
and copy the code:
```python from flask import request from htmlparsing import Attr, Text from toapi import Api, Item
api = Api()
@api.site('https://news.ycombinator.com') @api.list('.athing') @api.route('/posts?page={page}', '/news?p={page}') @api.route('/posts', '/news?p=1') class Post(Item): url = Attr('.storylink', 'href') title = Text('.storylink')
@api.site('https://news.ycombinator.com') @api.route('/posts?page={page}', '/news?p={page}') @api.route('/posts', '/news?p=1') class Page(Item): next_page = Attr('.morelink', 'href')
def clean_next_page(self, value):
return api.convert_string('/' + value, '/news?p={page}', request.host_url.strip('/') + '/posts?page={page}')
api.run(debug=True, host='0.0.0.0', port=5000) ```
run python app.py
then open your browser and visit http://127.0.0.1:5000/posts?page=1
you will get the result like:
json
{
"Page": {
"next_page": "http://127.0.0.1:5000/posts?page=2"
},
"Post": [
{
"title": "Mathematicians Crack the Cursed Curve",
"url": "https://www.quantamagazine.org/mathematicians-crack-the-cursed-curve-20171207/"
},
{
"title": "Stuffing a Tesla Drivetrain into a 1981 Honda Accord",
"url": "https://jalopnik.com/this-glorious-madman-stuffed-a-p85-tesla-drivetrain-int-1823461909"
}
]
}
Write code and test code and pull request.
well,may you see that your website is not accessed now! Maybe your project is not alive. It is so sad
Bumps ujson from 4.0.2 to 5.4.0.
Sourced from ujson's releases.
5.4.0
Added
- Add support for arbitrary size integers (#548)
@JustAnotherArchivist
Fixed
- CVE-2022-31116:
- Replace
wchar_t
string decoding implementation with auint32_t
-based one (#555)@JustAnotherArchivist
- Fix handling of surrogates on decoding (#550)
@JustAnotherArchivist
- CVE-2022-31117: Potential double free of buffer during string decoding
@JustAnotherArchivist
- Fix memory leak on encoding errors when the buffer was resized (#549)
@JustAnotherArchivist
- Integer parsing: always detect overflows (#544)
@NaN-git
- Fix handling of surrogates on encoding (#530)
@JustAnotherArchivist
5.3.0
Added
Changed
- Benchmark refactor - argparse CLI (#533)
@Erotemic
Fixed
- Fix segmentation faults when errors occur while handling unserialisable objects (#531)
@JustAnotherArchivist
- Fix segmentation fault when an exception is raised while converting a dict key to a string (#526)
@JustAnotherArchivist
- Fix memory leak dumping on non-string dict keys (#521)
@JustAnotherArchivist
- Fix ref counting on repeated default function calls (#524)
@JustAnotherArchivist
- Remove redundant
wheel
dependency frompyproject.toml
(#535)@hugovk
5.2.0
Added
- Support parsing NaN, Infinity and -Infinity (#514)
@Erotemic
- Support dynamically linking against system double-conversion library (#508)
@musicinmybrain
- Add env var to control stripping debug info (#507)
@musicinmybrain
- Add
JSONDecodeError
(#498)@JustAnotherArchivist
Fixed
- Fix buffer overflows (CVE-2021-45958) (#519)
@JustAnotherArchivist
- Upgrade Black to fix Click (#515)
@hugovk
- simplify exception handling on integer overflow (#510)
@RouquinBlanc
- Remove dead code that used to handle the separate int type in Python 2 (#509)
@JustAnotherArchivist
- Fix exceptions on encoding list or dict elements and non-overflow errors on int handling getting silenced (#505)
@JustAnotherArchivist
5.1.0
Changed
... (truncated)
9c20de0
Merge pull request from GHSA-fm67-cv37-96ffb21da40
Fix double free on string decoding if realloc fails67ec071
Merge pull request #555 from JustAnotherArchivist/fix-decode-surrogates-2bc7bdff
Replace wchar_t string decoding implementation with a uint32_t-based onecc70119
Merge pull request #548 from JustAnotherArchivist/arbitrary-ints4b5cccc
Merge pull request #553 from bwoodsend/pypy-ciabe26fc
Merge pull request #551 from bwoodsend/bye-bye-travis3efb5cc
Delete old TravisCI workflow and references.404de1a
xfail test_decode_surrogate_characters() on Windows PyPy.f7e66dc
Switch to musl docker base images.Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Closes #134
There is a small typo in docs/topics/storage.md.
Should read program
rather than programe
.
cssselect
PYPI package was not part of the install_requirements
list in setup.py
When I ran this example, I reported the following error
2019/09/19 10:15:50 [Register] OK
toapi, version 2.1.0 Flask 1.0.2 Python 3.6.0
html json api python web spider crawler flask toapi