patul
A tiny spider based on asyncio and requests.
install
pip install patul
usage
Just like scrapy:
import patul
class MySpider(patul.Spider):
start_urls = ['https://cn.bing.com/']
async def parse(self, response):
print(response.xpath('//a/@href').get())
yield patul.Request('https://github.com/financialfly/async-request', callback=self.parse_github)
def parse_github(self, response):
yield {'hello': 'github'}
async def process_result(self, result):
# Process result at here.
print(result)
if __name__ == '__main__':
# Run spider
patul.crawl(MySpider)
For more detailed control (like: handle cookies, download delay, concurrent requests, max retries, logs settings etc.): (refer to the constructor of the Crawler class):
import patul
class MySpider(patul.Spider):
...
if __name__ == '__main__':
patul.crawl(
MySpider,
handle_cookies=True,
download_delay=0,
concurrent_requests=10,
max_retries=3,
log_settings={'fp': 'spider.log'}
)
test
Use fetch function to get a response immediately:
from patul import fetch
def parse():
response = fetch('https://www.bing.com')
print(response)
parse()
the output will like this:
<Response 200 https://cn.bing.com/>
The fetch function also could be use like this:
import patul
def parse(response):
print(response)
yield patul.Request(response.url, callback=parse_next)
def parse_next(response):
print(response.status_code)
yield {'hello': 'world'}
patul.fetch('http://www.baidu.com', callback=parse)
then run the script, you will see the result:
<Response 200 http://www.baidu.com/>
200
Metadata
Release files for patul 0.1005
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| patul-0.1005.tar.gz | 6.3 kB | Without provenance | Details for patul-0.1005.tar.gz |
Release files / patul-0.1005.tar.gz
| Download URL | patul-0.1005.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2dd126e9f5d26287471ba7172efd9ca3c0b6382dab1be0e484cfe5eac2a2680f
|
|
BLAKE2b-256 checksum How to use checksums |
d6e439f34652dd77e5d3ed629517748f7b0784f2e98a4a62eb823c2a55db8f98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.14.2 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
|
Security for patul 0.1005
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.