我正在尝试抓取url以获取所有分支的地址和branch_name。
URL =“ https://www.uob.co.id/personal/branch-and-atm-locator.page”
从网络选项中,我找到了所请求的URL路径: URL =“ https://www.uob.co.id/wsm/stayinformed.do?path=lokasicabangatm” 但此处显示数据的格式尚不清楚。
import requests
from bs4 import BeautifulSoup
r = requests.get(URL)
soup = BeautifulSoup(r.content)
print(soup)
如何提取相关信息?
答案 0 :(得分:1)
只需将响应转储到.csv
文件中,您就可以拥有所有数据。
import requests
headers = {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36",
}
response = requests.get("https://www.uob.co.id/wsm/stayinformed.do?path=lokasicabangatm", headers=headers).text
with open("data.csv", "w") as f:
f.write(response)
输出: