python - 从网站的多个页面中提取电子邮件并列出
问题描述
我想使用 python 从展览网站中提取参展商的电子邮件。该页面包含参展商的超文本。点击参展商名称后,您将找到包含其电子邮件的参展商资料。
你可以在这里找到网站:
请问如何使用python做到这一点?先感谢您
解决方案
您可以获取所有参展商的链接,然后遍历这些链接并提取每个参展商的电子邮件:
import requests
import bs4
url = 'https://www.medica-tradefair.com/cgi-bin/md_medica/lib/pub/tt.cgi/Exhibitor_index_A-Z.html?oid=80398&lang=2&ticket=g_u_e_s_t'
response = requests.get(url)
soup = bs4.BeautifulSoup(response.text, 'html.parser')
links = soup.find_all('a', href=True)
exhibitor_links = ['https://www.medica-tradefair.com'+link['href'] for link in links if 'vis/v1/en/exhibitors' in link['href'] ]
exhibitor_links = list(set(exhibitor_links))
for link in exhibitor_links:
response = requests.get(link)
soup = bs4.BeautifulSoup(response.text, 'html.parser')
name = soup.find('h1',{'itemprop':'name'}).text
try:
email = soup.find('a', {'itemprop':'email'}).text
except:
email = 'N/A'
print('Name: %s\tEmail: %s' %(name, email))
推荐阅读
- c++ - NPM 安装:找不到平台工具集 = v141
- java - 发布在 Facebook Java Android 上
- json - 用冒号从 Javascript 中的 JSON 对象读取属性
- python - 从多个 Rar 文件中收集评论数据而无需解压缩
- java - 错误 335544421。连接被远程接口拒绝
- c# - 使用 EF Core 加载未映射的属性
- multithreading - 如何同步插入/删除元素到数据结构,功能方式?
- paypal - 字段格式错误:在 payflow pro 中没有 BAID/Account Number/ORIGID 时无法创建 RB Profile
- python - 从宽到长重塑熊猫数据框
- angular - 在 Angular 中以编程方式加载子组件