Noble TLS 使用教程

Noble TLS 使用教程

noble-tlsA sophisticated asynchronous HTTP library, based on requests and tls-client. Automatically updates JA3 fingerprints.项目地址:https://gitcode.com/gh_mirrors/no/noble-tls

1、项目介绍

Noble TLS 是一个基于 requeststls-client 的高级异步 HTTP 库。它提供了自动更新 JA3 指纹的功能,支持异步操作、代理、自定义 JA3 字符串、自定义 H2 设置等多种高级特性。Noble TLS 的设计灵感来源于 requests,因此其语法与 requests 非常相似,使用起来非常方便。

2、项目快速启动

安装

首先,你需要安装 Noble TLS 库。你可以通过 pip 进行安装:

pip install noble-tls

基本使用

以下是一个简单的示例,展示了如何使用 Noble TLS 进行基本的 HTTP GET 请求:

import noble_tls
from noble_tls import Client

async def main():
    await noble_tls.update_if_necessary()  # 更新 TLS 客户端库
    session = noble_tls.Session(client=Client.CHROME_111, random_tls_extension_order=True)
    res = await session.get("https://example.com/", headers={"key1": "value1"}, proxy="http://user:password@host:port")
    print(res.text)

# 运行主函数
import asyncio
asyncio.run(main())

3、应用案例和最佳实践

应用案例

Noble TLS 可以用于各种需要高级 HTTP 功能的场景,例如爬虫、API 调用、自动化测试等。以下是一个使用自定义 JA3 字符串的示例:

import noble_tls

async def main():
    await noble_tls.update_if_necessary()  # 更新 TLS 客户端库
    session = noble_tls.Session(
        ja3_string="771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0",
        h2_settings={"HEADER_TABLE_SIZE": 65536, "MAX_CONCURRENT_STREAMS": 1000}
    )
    res = await session.get("https://example.com/")
    print(res.text)

# 运行主函数
import asyncio
asyncio.run(main())

最佳实践

  • 自动更新:使用 await noble_tls.update_if_necessary() 确保 TLS 客户端库始终是最新的。
  • 自定义设置:根据需要自定义 JA3 字符串、H2 设置等,以满足特定需求。
  • 错误处理:在实际应用中,建议添加错误处理逻辑,以应对网络请求中可能出现的各种异常情况。

4、典型生态项目

Noble TLS 可以与其他 Python 生态项目结合使用,例如:

  • Scrapy:结合 Scrapy 进行更高效的网页抓取。
  • FastAPI:在 FastAPI 项目中使用 Noble TLS 进行外部 API 调用。
  • Selenium:与 Selenium 结合,进行更复杂的自动化测试。

通过这些生态项目的结合,可以进一步扩展 Noble TLS 的应用场景,提升开发效率和功能丰富性。

noble-tlsA sophisticated asynchronous HTTP library, based on requests and tls-client. Automatically updates JA3 fingerprints.项目地址:https://gitcode.com/gh_mirrors/no/noble-tls

  • 11
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
As an AI language model, I do not have personal experience with using Noble, but I can provide you with some information on how to use it. Noble is a Node.js library for interacting with Bluetooth Low Energy (BLE) devices. It provides a high-level API for connecting to and communicating with BLE devices. Here are the basic steps to use Noble: 1. Install Noble: You can install Noble using the npm package manager by running the following command: npm install noble 2. Scan for devices: Use Noble's startScanning() method to scan for nearby BLE devices. You can also filter the results by specifying the device's service UUID or MAC address. 3. Connect to a device: Once you have found a device, use Noble's connect() method to establish a connection. 4. Discover services and characteristics: Use Noble's discoverServices() and discoverCharacteristics() methods to discover the available services and characteristics of the connected device. 5. Read and write data: Once you have discovered a characteristic, you can read or write data to it using Noble's read() and write() methods. 6. Disconnect: Use Noble's disconnect() method to close the connection to the device. Here is an example code snippet that demonstrates how to use Noble: ```javascript const noble = require('noble'); noble.on('stateChange', function(state) { if (state === 'poweredOn') { noble.startScanning(); } else { noble.stopScanning(); } }); noble.on('discover', function(peripheral) { console.log('Found device with local name: ' + peripheral.advertisement.localName); console.log('Device ID: ' + peripheral.id); console.log('Device address: ' + peripheral.address); peripheral.connect(function(error) { console.log('Connected to device'); peripheral.discoverServices([], function(error, services) { services.forEach(function(service) { console.log('Found service: ' + service.uuid); service.discoverCharacteristics([], function(error, characteristics) { characteristics.forEach(function(characteristic) { console.log('Found characteristic: ' + characteristic.uuid); characteristic.read(function(error, data) { console.log('Characteristic value: ' + data.toString('hex')); }); }); }); }); }); }); }); ``` This code snippet scans for nearby BLE devices, connects to a device, discovers the available services and characteristics, and reads the value of each characteristic.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

裘旻烁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值