自定义邮件抓取工具无法获取目标邮件

custom mail scrapper tool is unable to get targeting mails

提问人:Fhyruz 提问时间:11/2/2023 更新时间:11/2/2023 访问量:15

问:

我正在尝试在我的 python 系统中运行此代码(这是来自网站的代码,我正在尝试运行它以用于理解目的)。但是我没有收到任何废弃的电子邮件或子域。它只是在第一次尝试后终止。谁能帮我?

from bs4 import BeautifulSoup
import requests
import requests.exceptions
import urllib.parse
from collections import deque
import re

user_url= str(input('[+]Enter targer URL to scan: '))
urls= deque([user_url])

#two puposes 1.visiting the url and 2.extracting email

scrapped_url= set()  
email= set()       

count= 0

try:
        
    while len(urls):
        count += 1

        if count == 100:
            break

        url= urls.popleft()
        scrapped_url.add(url)

        parts= urllib.parse.urlsplit(url)
        base_url = '{0.scheme}://{0.netloc}'.format(parts)

        path= url[:url.rfind('/')+1] if '/' in parts.path else url
        print('[%d] Processsing %s' % (count, url))
        
        try:
            response= requests.get(url)

        except(requests.exceptions.MissingSchema, requests.exceptions.ConnectionError):
            continue

        new_emails = set(re.findall(r'[a-z0-9\. \-+_]+@[a-z0-9\. \-+_]+\.[a-z]+', response.text, re.I))
        email.update(new_emails)

        soup= BeautifulSoup(response.text, features="lxml")

        for anchor in soup.find_all("a"):
            link= anchor.attrs['href'] if 'href' in anchor.attrs else ''
        if link.startswith('/'):
            link= base_url+ link
        elif not link.startswith('http'):
            link = path + link
            if not link in urls and not link in scrapped_url:
                urls.append(link)
except KeyboardInterrupt:
    print('[-] Closing!')

    for mail in email:
        print(mail)
Python 电子邮件

评论

0赞 Matthias 11/3/2023
您是否知道您只检查您找到的最后一个链接?这是对的吗?循环后的值是多少?如果它是一个内部链接(以“/”开头),你甚至不会进一步点击该链接。soup.find_all("a")linkfor
0赞 Matthias 11/3/2023
此外:只有在收到 .KeyboardInterrupt
1赞 tripleee 11/3/2023
你要找的动词是“刮”;“报废”某物就是丢弃它。
0赞 Matthias 11/3/2023
如果你纠正了错误的缩进,它会以某种方式工作。如果你不知道要纠正什么,那么这段代码超出了你目前的知识水平,你应该回到本教程。

答: 暂无答案