Skip to main content

No project description provided

Project description

Python requests.HTTPAdapter for acw_sc__v2

acw_sc__v2 is a cookie used by some websites to prevent crawlers. When the website detects that the request is sent by a crawler, it returns a javascript challenge. The crawler needs to solve the challenge and resend the request with the cookie set to the challenge value. This project provides a Python requests.HTTPAdapter to resolve the challenge automatically.

Usage

pip install acw-sc-v2-py
import requests

session = requests.Session()

# add the following code to your original requests code
from acw_sc_v2_py import acw_sc__v2 
adapter = acw_sc__v2.AcwScV2Adapter()
session.mont("http://", adapter)
session.mount("https://", adapter)

response = session.get("https://www.example.com/")
print(response.text)

Use Case

Before using acw-sc-v2-py

import requests

session = requests.Session()

for i in range(8):
    response = session.get("https://www.example.com/")
    print(response.text)

Usually, you will get blocked after sending 2 consecutive requests to the same website. The response will be like the following HTML code which requires you to solve a javascript challenge. If the web page is opened in a browser, the browser will automatically solve the challenge.

<html><script>
var arg1='70D9569CD5E5895C84F284A09503B1598C5762A1';
var _0x4818=['\x63\x73\x4b\x48\x77\x71\x4d\x49,...
function setCookie(name,value){var expiredate=new Date();...
function reload(x) {setCookie("acw_sc__v2", x);...
</script></html>

After using acw-sc-v2-py

import requests
# step 1: import
from acw_sc_v2_py import acw_sc__v2 

session = requests.Session()

# step 2: create adapter
adapter = acw_sc__v2.AcwScV2Adapter()

# step 3: mount adapter
session.mont("http://", adapter)
session.mount("https://", adapter)

for i in range(8):
    response = session.get("https://www.example.com/")
    print(response.text)

By using acw-sc-v2-py, you will get the normal response. The acw_sc__v2 will handle the javascript challenge and automatically update the cookie.

Enable logging

Prepend the following code to enable detailed log for acw-sc-v2-py.

import logging
logger = logging.getLogger("acw_sc_v2_py.acw_sc__v2")
logger.setLevel(logging.DEBUG)
logger.propagate = True

import requests
from acw_sc_v2_py import acw_sc__v2 

session = requests.Session()

adapter = acw_sc__v2.AcwScV2Adapter()
session.mont("http://", adapter)
session.mount("https://", adapter)

for i in range(8):
    response = session.get("https://www.example.com/")
    print(response.text)

The log will be like the following.

[2024-01-26 22:01:26] INFO:root:detected anti spam is triggered
[2024-01-26 22:01:28] INFO:root:cookie generated acw_sc__v2=65b3bb3601fe9ab002c5c1ff58fc71a1115e8322
[2024-01-26 22:01:28] INFO:root:resending the origin request
<!DOCTYPE html></html>
[2024-01-26 22:01:29] INFO:root:cookie set acw_sc__v2=65b3bb3601fe9ab002c5c1ff58fc71a1115e8322
[2024-01-26 22:01:30] INFO:root:anti spam is not triggered
<!DOCTYPE html></html>
...

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

acw_sc_v2_py-0.0.5.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

acw_sc_v2_py-0.0.5-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file acw_sc_v2_py-0.0.5.tar.gz.

File metadata

  • Download URL: acw_sc_v2_py-0.0.5.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.11 Linux/6.5.0-14-generic

File hashes

Hashes for acw_sc_v2_py-0.0.5.tar.gz
Algorithm Hash digest
SHA256 472e0e97f01ca15e1b00fcb568084f3ec9137bac83996ffbd42339338181a54a
MD5 4af06d79dad17b4e6d67359a062375ed
BLAKE2b-256 6f762abd04bf0928466bc112e7718308e9d5dc19a4eaedfa6549591ecb459edc

See more details on using hashes here.

File details

Details for the file acw_sc_v2_py-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: acw_sc_v2_py-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.11 Linux/6.5.0-14-generic

File hashes

Hashes for acw_sc_v2_py-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 aa7a315a4e4f0d29c2a05f80c57dc2b35b16d6ee1b8a32a27dc3966069b6ee17
MD5 fb6c62bda95f4c5b19c6c304780e45a3
BLAKE2b-256 daf151c357d68931b4ae8f6e037b9a649c20a282db7bd4d38528d0b724432288

See more details on using hashes here.

Supported by

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