Skip to main content

BeautifulSoup + requests + tqdm + pandas的一個庫

Project description

爬蟲相關庫

這個專案包含了一些用於網頁爬蟲的實用工具和類別。

主要功能

  1. Bug 類別:用於設置和管理爬蟲請求。
  2. 檔案下載:支援從網頁下載檔案。
  3. Excel 輸出:可將爬取的數據輸出為 Excel 檔案。
  4. 環境變數管理:安全地獲取環境變數。
  5. 鏈接檢查:驗證 URL 的有效性。

安裝指南

  1. 確保您的系統已安裝 Python 3.6 或更高版本。

  2. 使用 pip 安裝套件:

pip install hsuBug

使用示例

基本爬蟲設置

from hsuBug import Bug

# 創建 Bug 實例
url = "https://example.com"
bug = Bug(url)

# 設置請求頭
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}

# 設置並獲取網頁內容
bug.setup(headers)

# 現在您可以使用 bug.soup 來解析 HTML 內容

下載檔案

from hsuBug.functions import downloadFile

url = "https://example.com/file.pdf"
filename = "example.pdf"
downloaded_file = downloadFile(url, filename)
print(f"檔案下載至:{downloaded_file}")

輸出到 Excel

from hsuBug.functions import downloadByExcel

data = {
    "名稱": ["項目1", "項目2", "項目3"],
    "價格": [100, 200, 300]
}

df = downloadByExcel(data)
if df is not None:
    print("數據已成功輸出到 Excel 檔案")

檢查鏈接有效性

from hsuBug.functions import checkLink

url = "https://example.com"
if checkLink(url):
    print("鏈接有效")
else:
    print("鏈接無效")

單元測試

python -m unittest test_hsuBug.py

發布

python setup.py sdist
twine upload dist/*

未來功能

  1. aiohttp 版本

許可證

MIT

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

hsuBug-0.1.5.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file hsuBug-0.1.5.tar.gz.

File metadata

  • Download URL: hsuBug-0.1.5.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for hsuBug-0.1.5.tar.gz
Algorithm Hash digest
SHA256 324650b49a368c015ea2e6f8e549656d24361f460d2872dbad26105b8be13935
MD5 8cb85f96e4e10584f85a796f3f16a5ce
BLAKE2b-256 c7bf8a541599fce066f01260c14794767d18cd90ae617c0434ad9aeee687db28

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