【发布时间】:2017-02-01 08:23:00
【问题描述】:
希望你一切都好。我是 Python 新手,使用的是 python 2.7。
我正在尝试仅从该公共网站业务目录中提取 mailto:http://www.tecomdirectory.com/companies.php?segment=&activity=&search=category&submit=Search
我要查找的邮件是完整目录中从 a-z 开始的每个小部件中提到的电子邮件。不幸的是,这个目录没有 API。
我正在使用 BeautifulSoup,但到目前为止没有成功。
这是我的代码:
import urllib
from bs4 import BeautifulSoup
website = raw_input("Type website here:>\n")
html = urllib.urlopen('http://'+ website).read()
soup = BeautifulSoup(html)
tags = soup('a')
for tag in tags:
print tag.get('href', None)
我得到的只是实际网站的网站,例如 http://www.tecomdirectory.com 和其他 href 而不是小部件中的 mailto 或网站。我也尝试用汤('目标')替换汤('a'),但没有运气!有人可以帮帮我吗?
【问题讨论】:
-
嗨!谢谢回复!在我读 php 的 URL 中?所以我认为其中可能有一些php!如果没有,对不起!在编码中仍然是新的。问候
-
您好,能否请您确认我没有涉及 php,以便我可以编辑删除 php 标签的问题?
标签: python python-2.7 web-scraping beautifulsoup