简体中文
使用 Bright Data 和 BeautifulSoup 来增强您的网页爬取工作流程。本指南将指导您如何在 Python 脚本中集成 Bright Data 代理,以确保安全、可靠和匿名的数据采集。
展开以获取您的 Bright Data 代理访问信息
PROXY ERROR
requests
pip install beautifulsoup4 requests
http://brd.superproxy.io/
your-username-country-US
proxy = { "http": "http://[USERNAME]:[PASSWORD]@[HOST]:[PORT]" }
import requests from bs4 import BeautifulSoup # Bright Data 代理配置 proxy = { "http": "http://[USERNAME]:[PASSWORD]@[HOST]:[PORT]", "https": "http://[USERNAME]:[PASSWORD]@[HOST]:[PORT]" } # 目标 URL(用于验证代理) url = "https://httpbin.org/ip" try: # 使用代理发送请求 response = requests.get(url, proxies=proxy, timeout=10) response.raise_for_status() # 处理 HTTP 错误 # 解析 HTML 内容 soup = BeautifulSoup(response.text, "html.parser") # 打印格式化的页面内容 print("响应内容(IP 地址):") print(soup.prettify()) except requests.exceptions.RequestException as e: print("使用代理时发生错误:", e)
{ "origin": "123.45.67.89" }
此页面对您有帮助吗?