试图找出此页面背后的逻辑:
我们已将一些结果存储在以下数据库中:
从 a到z大约:120个结果或更多:
我们必须使用哪些选项来获取数据
https://www.raiffeisen .ch/zuerich/de.html#bankselector-focus-titlebar
Raiffeisenbank Zürich
Limmatquai 68
8001Zürich
Tel. +41 43 244 78 78
[email protected]
https://www.raiffeisen.ch/sennwald/de.html
Raiffeisenbank Sennwald
Äugstisriet 7
9466Sennwald
Tel. +41 81 750 40 40
[email protected]
BIC/Swift Code: RAIFCH22XXX
https://www.raiffeisen.ch/basel/de/ueber -uns/engagement.html#bankselector-focus-titlebar
Raiffeisenbank Basel
St. Jakobs-Strasse 7
4052Basel
Tel. +41 61 226 27 28
[email protected]
嗯 - 我认为 - 如果以某种方式将所有内容都封装在 url 编码块中...
好吧,我正在尝试找出它 - 这是我的方法:
import requests
from bs4 import BeautifulSoup
def get_raiffeisen_data(url):
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
banks = []
# Find all bank entries
bank_entries = soup.find_all('div', class_='bank-entry')
for entry in bank_entries:
bank = {}
bank['name'] = entry.find('h2', class_='bank-name').text.strip()
bank['address'] = entry.find('div', class_='bank-address').text.strip()
bank['tel'] = entry.find('div', class_='bank-tel').text.strip()
bank['email'] = entry.find('a', class_='bank-email').text.strip()
banks.append(bank)
return banks
else:
print(f"Failed to retrieve data from {url}")
return None
url = 'https://www.raiffeisen.ch/rch/de/ueber-uns/raiffeisen-gruppe/organisation/raiffeisenbanken/deutsche-schweiz.html'
banks_data = get_raiffeisen_data(url)
for bank in banks_data:
print(f"Name: {bank['name']}")
print(f"Address: {bank['address']}")
print(f"Tel: {bank['tel']}")
print(f"Email: {bank['email']}")
print('-' * 40)
提供的代码示例无法使用,因为它假设数据直接嵌入在提供的初始 URL 的 HTML 中。但是,根据的描述,数据似乎是从其他地方动态加载的。
为了从 Raiffeisen 网站抓取所有 ~120 家银行的数据,需要确定加载这些数据的机制。这可能涉及以下一项或多项操作:
-
检查网站的 JavaScript 代码: 网站可能正在使用 JavaScript 向服务器发出 AJAX 请求以检索银行数据。可以使用浏览器的开发者工具(网络选项卡)来分析网站发出的网络请求,并识别检索银行数据的请求。
-
查找隐藏的 API 端点: 有些网站使用 API 来提供数据。通过分析网络请求,可以找到提供银行数据的隐藏 API 端点。
-
逆向工程网站的 JavaScript 代码: 如果数据是使用复杂逻辑或混淆的 JavaScript 代码加载的,可能需要花费更多精力来理解代码的工作原理,并复制加载数据的逻辑。
找到加载数据的机制后,可以使用 Python 和
requests
库来模拟这些请求,并使用 Beautiful Soup 或其他解析库(例如 lxml 或 json)来提取数据。
以下是一些可能帮助进行调查的附加提示:
- 搜索特定关键字: 在网络选项卡中,尝试搜索“bank”、“location”或“branch”等关键字,以过滤与加载银行数据相关的请求。
- 检查请求头和参数: 分析网络请求中的请求头和参数,以查看是否有任何模式或唯一标识符用于检索特定数据。
- 使用调试器: 使用浏览器的 JavaScript 调试器来设置断点并逐步执行代码,以了解数据加载过程。
请记住,抓取网站时请务必遵守其服务条款和 robots.txt 文件。
标签:python,pandas,web-scraping,beautifulsoup From: 78788919