弹出/模态/对话框窗口数据抓取

时间:2020-10-28 17:44:31

标签: javascript python jquery beautifulsoup

是否可以从弹出窗口,模态窗口或对话框窗口中剪贴数据?

例如

https://tenders.procurement.gov.ge/public/?lang=en

我需要来自用户>供应商的电子邮件地址,您可以看到用户列表,但是我必须打开弹出窗口才能检查有关用户的任何信息。

那么我该如何删除这些弹出窗口中的所有电子邮件?有可能吗?

第一个屏幕:
enter image description here

第二个屏幕:
enter image description here

第三屏:
enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用requests.session来完成任务:

import re
import requests
from bs4 import BeautifulSoup

base_url = 'https://tenders.procurement.gov.ge/public/?lang=en'
url = 'https://tenders.procurement.gov.ge/public/library/controller.php?action=org_list'
profile_url = 'https://tenders.procurement.gov.ge/public/library/controller.php?action=profile&org_id='
num = re.compile(r'(\d+)')

with requests.session() as s:
    
    # load cookies:
    s.get(base_url)
    
    soup = BeautifulSoup(s.get(url).content, 'html.parser')
    
    for tr in soup.select('tr[onclick]'):
        n = num.search(tr['onclick']).group(1)
        soup2 = BeautifulSoup(s.get(profile_url + n).content, 'html.parser')
        email = soup2.select_one('td:contains("E-Mail") + td')
        print(email.text)

打印:

xxx@yandex.ru
xxx@gmail.com
xxx@gmail.com

...and so on.