Skip to main content

Inherit the requests module, add xpath functionality to expand the API, and handle request failures and retries

Project description

Welcome to requestXpath !

Introduce

Package name: requestXpath Introduction: Inherit the requests module, add xpath functionality to expand the API, and handle request failures and retries

ProTip: Request to carry random useragent by default.

Introduction to Usage

Args Values notes
method Examle: "get" or "post" Type: string Request Method
url Examle: "http://www.example.com" Type: string Request Url
headers Type: dict Default Random Request Header
data Type: dict or string Request parameters
encoding Default: "utf-8" Type: string Request Encoding
retry_time Default: 3 Type: int Retry Count
retry_interval Default: 1 Type: int Retry Interval
timeout Default: 3 Type: int Request timeout
others *args or **kwargs Follow Requests

Get started

Install Package: pip install requestXpath Make a request:

from requestXpath import prequests
url = 'https://gitee.com/'
response = prequests.get(url=url)

GET Status Code

response.status_code

GET Text

response.text

GET Content

response.content

GET Url

response.url

GET History

response.history

GET Headers

response.headers

GET Text Length

response.get_len

GET Lxml Tree

response.tree

Xpath Api

Example

from requestXpath import prequests  
url = 'https://www.runoob.com/python3/python3-tutorial.html'  
response = prequests.get(url=url)  
tree = response.tree  
title = tree.xpath("//div[@id='content']/h1")
print(title)
# Python 3 教程

xpath parameter: x:xpath; filter:xpath filter;character: line feed;rule:re rule;is_list:reture list

  • According to Xpath syntax defaults to extracting text or @href,No //text() or /text()

     content = tree.xpath("//div[@class='tutintro']", filter="strong")
     <class 'str'>
     # Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。
     # ......
     # Python 2.X 版本的教程
     # 。
    
  • We can find it's gone strong node text

  • is_list: return list

     content = tree.xpath("//div[@class='tutintro']", filter="strong", is_list=True)
     <class 'list'>
     # ['Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。', 'Python 介绍及安装教程我们在', 'Python 2.X 版本的教程', '中已有介绍,这里就不再赘述。', '你也可以点击', 'Python2.x与3\u200b\u200b.x版本区别', '来查看两者的不同。', '本教程主要针对 Python 3.x 版本的学习,如果你使用的是 Python 2.x 版本请移步至', 'Python 2.X 版本的教程', '。']
    

xxpath

  • Native official usage

    tree.xxpath("xpath")
    

dpath

  • Date extraction

    tree.dpath("xpath")
    

Please contact me if there are any bugs

email -> 1944542244@qq.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requestXpath-0.1.2.2.tar.gz (51.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requestXpath-0.1.2.2-py3-none-any.whl (51.4 kB view details)

Uploaded Python 3

File details

Details for the file requestXpath-0.1.2.2.tar.gz.

File metadata

  • Download URL: requestXpath-0.1.2.2.tar.gz
  • Upload date:
  • Size: 51.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for requestXpath-0.1.2.2.tar.gz
Algorithm Hash digest
SHA256 e9167f36f6abc62b2c2c2cf4317cbb6cbb65ae26518674256126fa45c14371bf
MD5 7a9f85d4f1186eba18444c5a668512b2
BLAKE2b-256 add0f3d2e86bec461003ea0ebc1db8cbe9c662b07d83af1246da608ec0e56f2c

See more details on using hashes here.

File details

Details for the file requestXpath-0.1.2.2-py3-none-any.whl.

File metadata

  • Download URL: requestXpath-0.1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 51.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for requestXpath-0.1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c93bec467f633309f0ae92c08d0722e4a4c4154e884b4351233b48555c6403c
MD5 72b7e7942c093a8b92dacf6e895be103
BLAKE2b-256 299b7968f36923e291716779dce660f844b6cc15ff43e82492bba1148db4ec76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page