在Google搜索结果中查找和提取电子邮件和电话

时间:2018-08-01 17:32:29

标签: python html python-3.x search

#! /usr/bin/env python3

# lucky.py - Finding and extracting e-mails in Google search results.

import requests, sys, webbrowser, bs4, re, urllib, urllib.request

print('Googling...') # display text while downloading the Google page
res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv[1:]))
res.raise_for_status()

# Retrieve top search result links.
soup = bs4.BeautifulSoup(res.text, "html5lib")

# Finding and extracting e-mails in Google search results.
linkElems = soup.select('.r a')
numOpen = min(5, len(linkElems))
for i in range(numOpen):
    f = urllib.request.urlopen('http://google.com' + linkElems[i].get('href'))
    s = f.read().decode('utf-8')
    print(re.findall(r"\+\d{2}\s?0?\d{10}",s))
    print(re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}",s))

后4行均不能正常工作。您能推荐一下如何使用python3完成此程序的方法:  如果在相关网站上找到电子邮件,电子邮件将显示在python3中。

0 个答案:

没有答案