javascript 解析请求和BeautifulSoup,为什么电子邮件不能从链接中抓取[重复]

qyuhtwio  于 2024-01-05  发布在  Java
关注(0)|答案(1)|浏览(99)

此问题在此处已有答案

Scraping of protected email(3个答案)
3小时前关闭。

  • 我的脚本是不返回电子邮件字段,我想从网站刮.任何解决办法??*
from  bs4 import BeautifulSoup

import requests

url = 'https://www.kw.com/agent/UPA-6587385179144187908-1'

res = requests.get(url)

soup = BeautifulSoup(res.content,'html.parser')

name  = soup.find('div',class_='AgentContent__name').text.strip()

location = soup.find('div',class_='AgentContent__location').text.strip()

website = soup.find('a',class_='AgentInformation__factBody').attrs['href']

print(website)

print(name)

print(location)

字符串

  • 这就是我得到的 *

/cdn-cgi/l/email-protection#f18394909d94828590859482b199949895989093949d94df929e9c
海蒂·阿贝莱
坎贝尔,加利福尼亚州

fykwrbwg

fykwrbwg1#

所有的信息都在脚本块中,你可以得到你想要的一切。例如:

import requests
from bs4 import BeautifulSoup
import json

response = requests.get('https://www.kw.com/agent/UPA-6587385179144187908-1')
soup = BeautifulSoup(response.text, 'lxml')
json_data = json.loads(soup.find('script', {'id': '__NEXT_DATA__'}).get_text())
name = json_data['props']['pageProps']['agentData']['name']['full']
city = json_data['props']['pageProps']['agentData']['location']['city']
state = json_data['props']['pageProps']['agentData']['location']['state']
email = json_data['props']['pageProps']['agentData']['email']
website = json_data['props']['pageProps']['agentData']['website']
print(f"{name}, {city}, {state}, {email}, {website}")

字符串
输出值:

Heidi Abele, Campbell, CA, [email protected], https://heidiabelerealtor.com/

相关问题