一个使用 Google 搜索的 Python 公共代理解析器。我们将使用 googlesearch-python
库来执行谷歌搜索和 BeautifulSoup
用于 HTML 解析。
首先,确保您已经安装了必要的库:
pip install beautifulsoup4 google
现在,让我们创建代理解析器:
from googlesearch import search
from bs4 import BeautifulSoup
import requests
def fetch_proxies():
proxies = []
# Perform a Google search for public proxy lists
query = "public proxy list"
for url in search(query, num=5, stop=5, pause=2):
# Fetch the HTML content of the search result
try:
response = requests.get(url, timeout=10)
if response.status_code == 200:
html_content = response.text
# Parse the HTML using BeautifulSoup
soup = BeautifulSoup(html_content, 'html.parser')
# Find proxy IP addresses and ports
for row in soup.find_all('tr'):
cols = row.find_all('td')
if len(cols) >= 2:
proxy = cols[0].text.strip() + ':' + cols[1].text.strip()
proxies.append(proxy)
except Exception as e:
print(f"Error fetching proxies from {url}: {e}")
return proxies
if __name__ == "__main__":
proxies = fetch_proxies()
for proxy in proxies:
print(proxy)
此脚本将执行 Google 搜索公共代理列表,解析搜索结果的 HTML,并提取代理的 IP 地址和端口。请注意,使用此方法获得的代理的质量和可靠性可能会有所不同。此外,请务必负责任地使用代理,并遵守您通过它们访问的网站的服务条款。
评论 (0)
这里还没有评论,你可以成为第一个评论者!