獲得令牌后,打開命令提示符或終端,復(fù)制下面的命令行,替換 USER_TOKEN 使用您之前獲得的令牌,然后按 Enter 執(zhí)行代碼,將完成Crawlbase Scraper API的調(diào)用:

curl -x “http://USER_TOKEN@smartproxy.crawlbase.com:8012" -k “https://aliexpress.com/w/wholesale-macbook-pro.html”

本篇 curl 命令將通過 Crawlbase 的智能代理向您的目標(biāo) URL 發(fā)出 HTTP 請求。 代理設(shè)置為運行于 smartproxy.crawlbase.com 在港口 8012,并 -k 選項告訴 curl 忽略 SSL 證書驗證。 當(dāng)通過 HTTPS 連接到服務(wù)器并且您不想驗證服務(wù)器證書的真實性時使用它。

在 Crawlbase 的智能代理上下文中,禁用 SSL 驗證至關(guān)重要。 否則可能會阻礙智能代理和您的應(yīng)用程序之間的交互。

成功執(zhí)行后,您應(yīng)該收到來自的 HTML 響應(yīng) 全球速賣通 類似于此屏幕截圖中顯示的內(nèi)容:

為智能代理請求添加參數(shù)

由于Crawlbase Scraper API 將您的請求轉(zhuǎn)發(fā)到 抓取 API,它還受益于 Crawling API 的大部分功能。 您可以通過發(fā)送特定指令來微調(diào)您的請求,稱為 參數(shù),通過一個名為 CrawlbaseAPI-Parameters.

這可以讓您準(zhǔn)確地告訴智能代理您希望它如何處理您的請求。 您可以對其進行自定義以完美滿足您的需求。

在這種情況下,我們將使用一個名為 scraper=aliexpress-serp。 這告訴智能代理提取網(wǎng)站的響應(yīng)并以易于理解的方式組織它。 這就像要求 Smart Proxy 將雜亂的網(wǎng)站數(shù)據(jù)轉(zhuǎn)變?yōu)檎R且有組織的信息。

curl -H “CrawlbaseAPI-參數(shù):scraper=aliexpress-serp” -x “http://USER_TOKEN@smartproxy.crawlbase.com:8012" -k “https://aliexpress.com/w/wholesale-macbook-pro.html”

如何從 Crawlbase 庫導(dǎo)入不同的 API?

要從 Crawlbase 庫導(dǎo)入各種功能,您需要引用項目所需的特定 API。只需按照這些定制步驟操作即可。

導(dǎo)入 API 的步驟

  1. 安裝crawlbase:確保您已在 Python 環(huán)境中安裝了該庫。
pip install crawlbase
  1. 導(dǎo)入特定 API:利用fromPython 中的語句引入您需要的 API。
from crawlbase import CrawlingAPI, ScraperAPI, LeadsAPI, ScreenshotsAPI, StorageAPI

導(dǎo)入語句示例

from crawlbase import CrawlingAPI
from crawlbase import ScraperAPI
from crawlbase import LeadsAPI
from crawlbase import ScreenshotsAPI
from crawlbase import StorageAPI

通過遵循這些步驟,您可以輕松地將 Crawlbase 庫中必要的功能集成到您的項目中,確保您可以訪問根據(jù)您的需求定制的各種 API 功能。

使用 Python 調(diào)用 Crawlbase Scraper API

步驟 1. 配置您的 Python 項目

現(xiàn)在我們已經(jīng)討論了智能代理如何運行的基本細(xì)節(jié)。 我們已準(zhǔn)備好設(shè)置 Python 環(huán)境。

首先確保您有 Python 安裝在您的機器上。 如果這是您第一次使用 Python,我們推薦我們的 Python 初學(xué)者指南 并按照有關(guān)如何在系統(tǒng)上正確設(shè)置 Python 的分步過程進行操作。

步驟 2. 設(shè)置項目目錄

在計算機上配置 Python 后,我們現(xiàn)在需要設(shè)置一個新項目。 打開控制臺或終端并執(zhí)行以下命令。

mkdir crawbase

接下來,執(zhí)行下面的命令。

cd 文件夾名稱 
touch crawlbase.py

因此,當(dāng)您運行這行代碼時,它會執(zhí)行兩件事:

  1. 它將當(dāng)前目錄更改為“文件夾名稱”指定的目錄。
  2. 它在該目錄中創(chuàng)建一個名為“crawlbase.py”的新的空 Python 文件。

步驟3.安裝依賴項

要從 AliExpress 網(wǎng)頁檢索數(shù)據(jù)并將其保存到 JSON 文件,我們需要兩個基本包。

要求:這個包簡化了發(fā)送HTTP/1.1請求的過程。 您不必手動將查詢字符串添加到 URL 或?qū)?PUT 和 POST 數(shù)據(jù)進行編碼。 為了簡單起見,您可以只使用 json 方法。

JSON:Python 本身支持 JSON。 它帶有一個名為 json 的內(nèi)置包,用于編碼和解碼 JSON 數(shù)據(jù),無需安裝額外的包。

如何使用 pip 安裝 Crawlbase?

請按照以下簡單的步驟使用 pip 安裝它:

  1. 打開終端或命令提示符:
  1. 確保已安裝 Python:
python --version
  1. 安裝Crawlbase使用pip:
pip install crawlbase

按照以下步驟操作即可在您的系統(tǒng)上啟動并運行,可供您的開發(fā)項目使用。

步驟 4. 通過 Python 使用智能代理

我們已經(jīng)可以開始編寫主要的 Python 代碼并集成智能代理調(diào)用了。

在上一節(jié)中,我們創(chuàng)建了一個名為 crawlbase.py。 找到此文件,復(fù)制下面的代碼并運行它以檢索所需的數(shù)據(jù)。

import requests

# replace with your Crawlbase user_token.
username = 'USER_TOKEN'
password = '' # password is empty, its not used for authentication.
proxy_auth = f'{username}:{password}'

url = 'https://nl.aliexpress.com/w/wholesale-macbook-pro.html'
proxy_url = f"http://{proxy_auth}@smartproxy.crawlbase.com:8012"
proxies = {"http": proxy_url, "https": proxy_url}

response = requests.get(url=url, proxies=proxies, verify=False)

print('Response Body: ', response.content)

導(dǎo)入 requests Library

該行導(dǎo)入 requests Library,它簡化了在 Python 中發(fā)出 HTTP 請求的過程。

設(shè)置代理身份驗證:

更換 'USER_TOKEN' 使用您實際的 Crawlbase 用戶令牌。 該令牌用于通過智能代理發(fā)出請求時進行身份驗證。 這 proxy_auth 然后,遵循基本身份驗證格式,將變量格式化為包含用戶名和空密碼。

定義 URL 和代理 URL:

設(shè)置代理:

我們推薦使用 proxies 創(chuàng)建字典來指定代理設(shè)置。 “http”和“https”都設(shè)置為使用相同的代理 URL。

提出請求:

打印響應(yīng)正文:

此行打印響應(yīng)的內(nèi)容,其中包括 HTML 或從指定 URL 檢索的數(shù)據(jù)。

如何在 Crawlbase 中初始化 ScraperAPI 類?

要開始使用 ScraperAPI 類,您需要通過使用身份驗證令牌創(chuàng)建類的實例來初始化它。這個過程很簡單,只需幾行代碼即可。

首先,請確保您手邊有 API 令牌。您將在身份驗證過程中需要用到它。

接下來,通過將令牌傳遞到類構(gòu)造函數(shù)來創(chuàng)建類的實例。以下是指導(dǎo)您的示例:

scraper_api = ScraperAPI({'token': 'YOUR_TOKEN'})

初始化該類后,您可以使用其方法執(zhí)行網(wǎng)頁抓取任務(wù)。例如,要從電子商務(wù)網(wǎng)站獲取產(chǎn)品詳細(xì)信息,您可以使用該get方法。

以下是從電子商務(wù)頁面檢索產(chǎn)品信息的方法:

response = scraper_api.get('https://www.example.com/product/12345')
if response['status_code'] == 200:
print(response['json']['name'])

在此代碼片段中:

關(guān)鍵要點

通過這些步驟,您已準(zhǔn)備好初始化并在 Web 抓取項目中使用 ScraperAPI 類。享受無縫數(shù)據(jù)提取!

如何使用 ScraperAPI 類發(fā)出 GET 請求?

要使用該類發(fā)出 GET 請求<mark style="color: #272B32; border-width: 1px; border-radius: 4px; box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 1px 2px -1px rgba(0, 0, 0, 0.1); background-color: #FED7AA; border-color: #FB923C;">ScraperAPI</mark>,您首先需要使用您的令牌初始化該類。

以下是分步指南:

  1. 初始化ScraperAPI:首先創(chuàng)建<mark style="color: #272B32; border-width: 1px; border-radius: 4px; box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 1px 2px -1px rgba(0, 0, 0, 0.1); background-color: #FED7AA; border-color: #FB923C;">ScraperAPI</mark>類的一個實例,并將您的令牌作為參數(shù)傳遞。
scraper_api = ScraperAPI({'token': 'YOUR_API_TOKEN'})
  1. 發(fā)出 GET 請求:使用實例get的方法scraper_api,提供您要抓取的網(wǎng)頁的 URL。
response = scraper_api.get('https://www.amazon.com/DualSense-Wireless-Controller-PlayStation-5/dp/B08FC6C75Y/')
  1. 檢查響應(yīng)狀態(tài)代碼:通過檢查狀態(tài)代碼是否為 200 來驗證請求是否成功。
if response['status_code'] == 200:
product_name = response['json']['name']
print(product_name)

代碼示例

# Step 1: Initialize the ScraperAPI class with your token
scraper_api = ScraperAPI({'token': 'YOUR_API_TOKEN'})

# Step 2: Make the GET request to the desired URL
response = scraper_api.get('https://www.amazon.com/DualSense-Wireless-Controller-PlayStation-5/dp/B08FC6C75Y/')

# Step 3: Check the response status code and print the product name
if response['status_code'] == 200:
product_name = response['json']['name']
print(product_name)

通過遵循這些步驟,您可以輕松地發(fā)出 GET 請求并使用該類檢索必要的信息<mark style="color: #272B32; border-width: 1px; border-radius: 4px; box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 1px 2px -1px rgba(0, 0, 0, 0.1); background-color: #FED7AA; border-color: #FB923C;">ScraperAPI</mark>

如何在 Crawlbase 中為 API 請求設(shè)置自定義超時?

自定義 API 請求的超時時間非常簡單。設(shè)置方法如下:

首先,當(dāng)您創(chuàng)建新 API 對象的實例時,您可以指定所需的超時。這是通過傳遞超時值(以秒為單位)作為配置對象的一部分來完成的。以下是示例:

api = CrawlingAPI({'token': 'YOUR_TOKEN', 'timeout': 120})

要點:

通過設(shè)置此參數(shù),您可以確保您的請求在超時之前等待指定的時間,這對于管理長或復(fù)雜的 API 調(diào)用特別有用。

步驟 5. 執(zhí)行 Python 代碼

crawlbase.py

代碼的成功響應(yīng)將獲取 AliExpress URL 的完整 HTML 源代碼并將其顯示在您的控制臺上。 該數(shù)據(jù)在大多數(shù)情況下還沒有用處,因為它很難剖析。 為了獲得更合理且易于閱讀的數(shù)據(jù),我們必須解析此響應(yīng)并將其轉(zhuǎn)換為結(jié)構(gòu)化數(shù)據(jù),然后將其存儲在數(shù)據(jù)庫中以便于檢索和分析。

步驟 6. 使用 AliExpress scraper 解析數(shù)據(jù)

此步驟將利用智能代理自動解析 AliExpress 數(shù)據(jù)的功能。 為此,我們只需要傳遞 scraper=速賣通-serp – CrawlbaseAPI-parameters 作為我們代碼中的標(biāo)題。 編輯你的 crawlbase.py 文件并粘貼下面的代碼。

import requests
import json

# replace with your Crawlbase user_token.
username = 'USER_TOKEN'
password = '' # password is empty, its not used for authentication.
proxy_auth = f'{username}:{password}'

url = 'https://nl.aliexpress.com/w/wholesale-macbook-pro.html'
proxy_url = f"http://{proxy_auth}@smartproxy.crawlbase.com:8012"
proxies = {"http": proxy_url, "https": proxy_url}

headers = {
"CrawlbaseAPI-Parameters": "scraper=aliexpress-serp"
}

response = requests.get(url=url, proxies=proxies,
headers=headers, verify=False)

data = json.loads(response.text)

print('Response Scraped Body: ', json.dumps(data, indent=4))

執(zhí)行此代碼后,響應(yīng)將采用 JSON 格式,如下所示:

{
"original_status": 200,
"pc_status": 200,
"url": "https://nl.aliexpress.com/w/wholesale-macbook-pro.html?spm=MI7V_IrIdoZgPjgbnB0s3Q&",
"body": {
"products": [
{
"title": "5 In 1 Usb C Hub Type C Naar 4K Hd Adapter Met Rj45 Netwerk 100M 1000M Ethernet Lan Oplader Adapter Voor Macbook Pro",
"price": {
"current": "\uffe11.27"
},
"url": "https://nl.aliexpress.com/item/1005005653517644.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-0&pdp_npi=4%40dis%21GBP%215.76%211.27%21%21%216.86%21%21%40210318ec16999696359782730e2cad%2112000033898457492%21sea%21UK%210%21AB&curPageLogUid=SwEz55KtOSLT",
"image": "https://ae04.alicdn.com/kf/Sbffa8b7a90564cff82ca0b7c2ece62038/5-in-1-USB-C-Hub-Type-C-To-4K-HD-Adapter-with-RJ45-Network-100M.jpg_220x220xz.jpg_.webp",
"shippingMessage": "Gratis verzending boven de \uffe18 \u00b7 Levering binnen 7 dagen",
"soldCount": 207,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005005653517644.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-0&pdp_npi=4%40dis%21GBP%215.76%211.27%21%21%216.86%21%21%40210318ec16999696359782730e2cad%2112000033898457492%21sea%21UK%210%21AB&curPageLogUid=SwEz55KtOSLT",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Getatek Usb C Hub 4K 60Hz Hdmi Docking Station Type C Naar Ethernet Poort Pd 100W Usb 3.2 Hub Adapter Voor Macbook Pro Xiaomi Lenovo",
"price": {
"current": "\uffe19.66"
},
"url": "https://nl.aliexpress.com/item/1005005980859268.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-1&pdp_npi=4%40dis%21GBP%2130.10%219.66%21%21%21261.78%21%21%40210318ec16999696359782730e2cad%2112000035159491762%21sea%21UK%210%21AB&curPageLogUid=zcTTJdwE54mt",
"image": "https://ae04.alicdn.com/kf/S07ec6c1f025748f591ba11f8c9289000U/Getatek-USB-C-Hub-4K-60Hz-HDMI-Docking-Station-Type-C-to-Ethernet-Port-PD-100W.jpg_220x220xz.jpg_.webp",
"shippingMessage": "Gratis verzending",
"soldCount": 261,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005005980859268.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-1&pdp_npi=4%40dis%21GBP%2130.10%219.66%21%21%21261.78%21%21%40210318ec16999696359782730e2cad%2112000035159491762%21sea%21UK%210%21AB&curPageLogUid=zcTTJdwE54mt",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "12-In-1 Usb C Hub Docking Station Hdmi-Compatibele Adapter 4K 30Hz Pd 100W Type-C Hub Usb 3.0 Splitter Voor Laptop Macbook Pro Air",
"price": {
"current": "\uffe113.92"
},
"url": "https://nl.aliexpress.com/item/1005006054738654.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-2&pdp_npi=4%40dis%21GBP%2136.62%2113.92%21%21%2143.63%21%21%40210318ec16999696359782730e2cad%2112000035520585565%21sea%21UK%210%21AB&curPageLogUid=YU2V7Z8Q7JSg",
"image": "https://ae04.alicdn.com/kf/S5a1cda79dd644150b8755030c9bdc68aJ/12-in-1-USB-C-HUB-Docking-Station-HDMI-compatible-Adapter-4K-30Hz-PD-100W-Type.jpg_220x220xz.jpg_.webp",
"shippingMessage": "Gratis verzending",
"soldCount": 47,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005006054738654.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-2&pdp_npi=4%40dis%21GBP%2136.62%2113.92%21%21%2143.63%21%21%40210318ec16999696359782730e2cad%2112000035520585565%21sea%21UK%210%21AB&curPageLogUid=YU2V7Z8Q7JSg",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Baseus Usb Type C Hub Naar Hdmi Compatibel Usb 3.0 Adapter 6 In 1 Type C Hub Dock Voor macbook Pro Air Usb C Splitter",
"price": {
"current": "\uffe16.46"
},
"url": "https://nl.aliexpress.com/item/1005005208865147.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-3&pdp_npi=4%40dis%21GBP%2137.49%216.46%21%21%21325.98%21%21%40210318ec16999696359782730e2cad%2112000032856872202%21sea%21UK%210%21AB&curPageLogUid=0JuHtQXjX8DN",
"image": "https://ae04.alicdn.com/kf/S72ff1470a93645d6b3afd70400d7a288N/Baseus-USB-Type-C-HUB-to-HDMI-compatible-USB-3-0-Adapter-6-in-1-Type.jpg_220x220xz.jpg_.webp",
"shippingMessage": "Gratis verzending boven de \uffe18 \u00b7 Levering binnen 5 dagen",
"soldCount": 900,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005005208865147.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-3&pdp_npi=4%40dis%21GBP%2137.49%216.46%21%21%21325.98%21%21%40210318ec16999696359782730e2cad%2112000032856872202%21sea%21UK%210%21AB&curPageLogUid=0JuHtQXjX8DN",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Huav 2024 Originele Laptop 13.3 Inch 360% Omgedraaid Ultralicht 2K Touchscreen 16G Met 2Tssd Intel N4120 Windows 10 11 Laptop",
"price": {
"current": "\uffe1270.74"
},
"url": "https://nl.aliexpress.com/item/1005006176614563.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&aem_p4p_detail=20231114054716531607197640720004634170&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-4&pdp_npi=4%40dis%21GBP%21356.23%21270.74%21%21%213097.62%21%21%40210318ec16999696359782730e2cad%2112000036140607614%21sea%21UK%210%21AB&curPageLogUid=CWtKq454SCOw&search_p4p_id=20231114054716531607197640720004634170_1",
"image": "https://ae04.alicdn.com/kf/S09eb548a999e407384e583126b354e73Y/HUAV-2024-Original-Laptop-13-3-inch-360-Flipped-Ultra-Light-2K-Touch-Screen-16G-Running.jpg_220x220xz.jpg_.webp",
"shippingMessage": "Gratis verzending",
"soldCount": 18,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005006176614563.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&aem_p4p_detail=20231114054716531607197640720004634170&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-4&pdp_npi=4%40dis%21GBP%21356.23%21270.74%21%21%213097.62%21%21%40210318ec16999696359782730e2cad%2112000036140607614%21sea%21UK%210%21AB&curPageLogUid=CWtKq454SCOw&search_p4p_id=20231114054716531607197640720004634170_1",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Usb Hub 3.0 4 Poorten Usb3.0 Multi Splitter Adapter Otg Voor Xiaomi Lenovo Macbook Pro 13 15 Air Pro Pc Computer Laptop Accessoires",
"price": {
"current": "\uffe12.74"
},
"url": "https://nl.aliexpress.com/item/1005006212928878.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-5&pdp_npi=4%40dis%21GBP%214.57%212.74%21%21%215.44%21%21%40210318ec16999696359782730e2cad%2112000036304475455%21sea%21UK%210%21AB&curPageLogUid=koszKvWCNDet",
"image": "https://ae04.alicdn.com/kf/S3a56023e42be4eff830bd6174528311bp/USB-HUB-3-0-4-Ports-USB3-0-Multi-Splitter-Adapter-OTG-For-Xiaomi-Lenovo-Macbook.jpg_220x220xz.jpg_.webp",
"shippingMessage": "12-dag levering over \uffe18.39",
"soldCount": 9,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005006212928878.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-5&pdp_npi=4%40dis%21GBP%214.57%212.74%21%21%215.44%21%21%40210318ec16999696359782730e2cad%2112000036304475455%21sea%21UK%210%21AB&curPageLogUid=koszKvWCNDet",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Usb C Hub Voor Stoomdek Dockingstation Type C Naar Hdmi-Compatibel 4K 60Hz Pd 100W Usb 3.0 Adapterkabel Voor Laptop Macbook Pro",
"price": {
"current": "\uffe17.57"
},
"url": "https://nl.aliexpress.com/item/1005005653434065.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-6&pdp_npi=4%40dis%21GBP%2120.45%217.57%21%21%2124.37%21%21%40210318ec16999696359782730e2cad%2112000033897379128%21sea%21UK%210%21AB&curPageLogUid=E6zEd5ZZ3wXs",
"image": "https://ae04.alicdn.com/kf/S73ea26b1e655401cb67152e3c2aa3f30i/USB-C-HUB-for-Steam-Deck-Docking-Station-Type-C-to-HDMI-compatible-4K-60Hz-PD.jpg_220x220xz.jpg_.webp",
"shippingMessage": "Gratis verzending",
"soldCount": 30,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005005653434065.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-6&pdp_npi=4%40dis%21GBP%2120.45%217.57%21%21%2124.37%21%21%40210318ec16999696359782730e2cad%2112000033897379128%21sea%21UK%210%21AB&curPageLogUid=E6zEd5ZZ3wXs",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Usb C Naar Ethernet Adapter Rj45 Naar Thunderbolt 3 Type C Gigabit Netwerk Lan 1000Mbps Converter Voor Macbook Pro/Air Samsung Galaxy",
"price": {
"current": "\uffe13.37"
},
"url": "https://nl.aliexpress.com/item/1005006224668700.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-7&pdp_npi=4%40dis%21GBP%2111.24%213.37%21%21%2197.76%21%21%40210318ec16999696359782730e2cad%2112000036356461171%21sea%21UK%210%21AB&curPageLogUid=PuUF5xuqSwIN",
"image": "https://ae04.alicdn.com/kf/S6a1bc693df814f689c8a28bb25ce9867L/USB-C-to-Ethernet-Adapter-RJ45-to-Thunderbolt-3-Type-C-Gigabit-Network-LAN-1000Mbps-Converter.jpg_220x220xz.jpg_.webp",
"shippingMessage": "12-dag levering over \uffe18.39",
"soldCount": null,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005006224668700.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-7&pdp_npi=4%40dis%21GBP%2111.24%213.37%21%21%2197.76%21%21%40210318ec16999696359782730e2cad%2112000036356461171%21sea%21UK%210%21AB&curPageLogUid=PuUF5xuqSwIN",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Minisopuru Hub Usb C Hub 10Gbps Hub Usb Type C Naar Usb 3.2 Pd 100W Adapter Voor Macbook Pro Imac Pc Accessoires Usb Hub",
"price": {
"current": "\uffe14.64"
},
"url": "https://nl.aliexpress.com/item/1005005883953605.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-8&pdp_npi=4%40dis%21GBP%2132.13%214.64%21%21%21279.37%21%21%40210318ec16999696359782730e2cad%2112000034711180884%21sea%21UK%210%21AB&curPageLogUid=QeKUEU8r5Hh8",
"image": "https://ae04.alicdn.com/kf/S13153af571704d17b2143b89918557785/Minisopuru-HUB-USB-C-Hub-10Gbps-Hub-USB-Type-C-to-USB-3-2-PD-100W.jpg_220x220xz.jpg_.webp",
"shippingMessage": "Gratis verzending boven de \uffe18 \u00b7 Levering binnen 7 dagen",
"soldCount": 600,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005005883953605.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-8&pdp_npi=4%40dis%21GBP%2132.13%214.64%21%21%21279.37%21%21%40210318ec16999696359782730e2cad%2112000034711180884%21sea%21UK%210%21AB&curPageLogUid=QeKUEU8r5Hh8",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
},
{
"title": "Screen Vervanging Compatibel Met Macbook Pro Air A1706 A1708 A1989 A2159 A2251 A2289 A2338 A1466 A1932 A2179 A2337 Lcd Display",
"price": {
"current": "\uffe1113.97"
},
"url": "https://nl.aliexpress.com/item/1005003836485026.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&aem_p4p_detail=20231114054716531607197640720004634170&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-9&pdp_npi=4%40dis%21GBP%21113.97%21113.97%21%21%21135.79%21%21%40210318ec16999696359782730e2cad%2112000031226615553%21sea%21UK%210%21AB&curPageLogUid=0LcWc3CWSgz3&search_p4p_id=20231114054716531607197640720004634170_2",
"image": "",
"shippingMessage": "Verzending: \uffe130.92",
"soldCount": 128,
"ratingValue": "",
"ratingLink": "https://nl.aliexpress.com/item/1005003836485026.html?algo_pvid=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9&aem_p4p_detail=20231114054716531607197640720004634170&algo_exp_id=fdb7f6a7-4ed1-4ca4-b128-a1adec7f7fd9-9&pdp_npi=4%40dis%21GBP%21113.97%21113.97%21%21%21135.79%21%21%40210318ec16999696359782730e2cad%2112000031226615553%21sea%21UK%210%21AB&curPageLogUid=0LcWc3CWSgz3&search_p4p_id=20231114054716531607197640720004634170_2",
"sellerInformation": {
"storeName": "",
"storeLink": null
}
}
],
"relatedSearches": [
{
"title": "adapter netsnoer",
"link": "https://nl.aliexpress.com/w/wholesale-adapter-netsnoer.html"
},
{
"title": "macbook lucht bezel",
"link": "https://nl.aliexpress.com/w/wholesale-macbook-air-bezel.html"
},
{
"title": "macbook oplader",
"link": "https://nl.aliexpress.com/w/wholesale-macbook-oplader.html"
},
{
"title": "usb onderdeel",
"link": "https://nl.aliexpress.com/w/wholesale-usb-c-onderdeel.html"
},
{
"title": "keyboard bescherming macbook air",
"link": "https://nl.aliexpress.com/w/wholesale-keyboard-bescherming-macbook-air.html"
},
{
"title": "usb naar type c splitter",
"link": "https://nl.aliexpress.com/w/wholesale-usb-naar-type-c-splitter.html"
},
{
"title": "mac poorten",
"link": "https://nl.aliexpress.com/w/wholesale-mac-poorten.html"
},
{
"title": "dell laptops",
"link": "https://nl.aliexpress.com/w/wholesale-dell-laptops.html"
},
{
"title": "magsafe oplader macbook pro",
"link": "https://nl.aliexpress.com/w/wholesale-magsafe-charger-macbook-pro.html"
},
{
"title": "macbook pro a1229",
"link": "https://nl.aliexpress.com/w/wholesale-macbook-pro-a1229.html"
},
{
"title": "macbook lucht m1 16 16",
"link": "https://nl.aliexpress.com/w/wholesale-macbook-air-m1-16-512.html"
},
{
"title": "macbook pro a1708 toetsenbord vervanging",
"link": "https://nl.aliexpress.com/w/wholesale-macbook-pro-a1708-keyboard-replacement.html"
}
],
"relatedCategories": []
}
}

步驟 7. 將解析的數(shù)據(jù)保存到 JSON 文件

當(dāng)然,我們不會讓數(shù)據(jù)白白浪費。 在此步驟中,我們將在代碼中添加幾行,以便我們可以安全地存儲抓取的數(shù)據(jù)以供以后使用。 回到你的 crawlbase.py 再次文件并粘貼下面的代碼。

import requests
import json

# replace with your user_token which you get from your dashboard.
username = 'USER_TOKEN'
password = '' # password is empty, its not used for authentication.
proxy_auth = f'{username}:{password}'

url = 'https://nl.aliexpress.com/w/wholesale-macbook-pro.html'
proxy_url = f"http://{proxy_auth}@smartproxy.crawlbase.com:8012"
proxies = {"http": proxy_url, "https": proxy_url}

headers = {
"CrawlbaseAPI-Parameters": "scraper=aliexpress-serp"
}

response = requests.get(url=url, proxies=proxies,
headers=headers, verify=False)

data = json.loads(response.text)

with open('scraped_data.json', 'w') as json_file:
json.dump(data, json_file)

print('Response Scraped Body: ', json.dumps(data, indent=4))

處理響應(yīng)并將其保存為 JSON:

總結(jié)

在這篇博客中,我們深入探討了Crawlbase Scraper API 的細(xì)節(jié)及其在提高 AliExpress 網(wǎng)頁抓取效率方面發(fā)揮的重要作用。

該分步指南提供了有關(guān)配置 Python 項目、設(shè)置項目目錄、安裝依賴項、與 Python 無縫使用智能代理、執(zhí)行代碼以及使用 AliExpress 網(wǎng)絡(luò)抓取工具高效解析抓取數(shù)據(jù)的深入介紹。最后一步是將解析后的數(shù)據(jù)保存到結(jié)構(gòu)化 JSON 文件中。

資料原文:https://crawlbase.com/blog/aliexpress-proxy-scraping/

上一篇:

法大大區(qū)塊鏈智能合約API:數(shù)字化合同管理的新紀(jì)元

下一篇:

怎么識別并攔截語音消息當(dāng)中的違規(guī)內(nèi)容
#你可能也喜歡這些API文章!

我們有何不同?

API服務(wù)商零注冊

多API并行試用

數(shù)據(jù)驅(qū)動選型,提升決策效率

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

對比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準(zhǔn)確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費