从网站的多个页面中提取电子邮件并将其列出

时间:2019-03-20 11:32:45

标签: python web-scraping scrapy python-requests web-crawler

我想使用python从展览网站中提取参展商的电子邮件。该页面包含参展商的超文本。单击参展商名称后,您将找到包含其电子邮件的参展商资料。

您可以在此处找到该网站:

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

请问如何使用python做到这一点? 预先谢谢

1 个答案:

答案 0 :(得分:0)

您可以获取指向参展商的所有链接,然后遍历这些链接并为每个参展商提取电子邮件:

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))
相关问题