최근 뉴스 크롤러 프로젝트를 진행 중인데 이 기능을 구현하고 싶습니다. 페이지 크롤링에 실패한 후 이 페이지의 URL을 이메일로 보내세요. 최종 렌더링은 다음과 같습니다. 분류 및 검색 예외를 용이하게 하기 위해 나중에 필터 레이블, 실패 상태 코드 등을 추가할 수 있습니다.
개발자는 이메일에 포함된 URL 및 스택 정보를 기반으로 크롤러 실패 원인을 분석할 수 있습니다.
서버가 다운됐나요?
아니면 크롤러의 Dom 구문 분석이 콘텐츠를 구문 분석하지 않습니까?
아니면 이 페이지에 정규 표현식을 적용할 수 없나요? SMTP 서비스
QQ 메일함을 열면 인증 코드가 생성됩니다. 코드 원래 이메일 비밀번호 대신 이 인증 코드를 사용하여 이메일에 연결하세요. 이렇게 하면 일반 텍스트 비밀번호를 사용하지 않아도 됩니다.
그런데 오류가 보고되었습니다
Properties props = new Properties(); // 开启debug调试 props.setProperty("mail.debug", "true"); // 发送服务器需要身份验证 props.setProperty("mail.smtp.auth", "true"); // 设置邮件服务器主机名 props.setProperty("mail.host", "smtp.qq.com"); // 发送邮件协议名称 props.setProperty("mail.transport.protocol", "smtp"); Session session = Session.getInstance(props); //邮件内容部分 Message msg = new MimeMessage(session); msg.setSubject("seenews 错误"); StringBuilder builder = new StringBuilder(); builder.append("url = " + "http://blog.csdn.net/never_cxb/article/details/50524571"); builder.append("页面爬虫错误"); builder.append("\n data " + TimeTool.getCurrentTime()); msg.setText(builder.toString()); //邮件发送者 msg.setFrom(new InternetAddress("**发送人的邮箱地址**")); //发送邮件 Transport transport = session.getTransport(); transport.connect("smtp.qq.com", "**发送人的邮箱地址**", "**你的邮箱密码或者授权码**"); transport.sendMessage(msg, new Address[] { new InternetAddress("**接收人的邮箱地址**") }); transport.close();
DEBUG SMTP: AUTH LOGIN command trace suppressed DEBUG SMTP: AUTH LOGIN failed Exception in thread "main" javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28
MailSSLSocketFactory sf = new MailSSLSocketFactory(); sf.setTrustAllHosts(true); props.put("mail.smtp.ssl.enable", "true"); props.put("mail.smtp.ssl.socketFactory", sf);
전체 코드 예제
DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.qq.com", port 465, isSSL true 220 smtp.qq.com Esmtp QQ Mail Server DEBUG SMTP: connected to host "smtp.qq.com", port: 465 ... data 2016-01-19 17:00:44 Tue . 250 Ok: queued as QUIT 221 Bye
가 도움이 되었습니다.
QQ 사서함으로 이메일을 보내는 Java 기반 JavaMail 구현에 대한 자세한 내용은 PHP 중국어 웹사이트를 참조하세요!