【发布时间】:2013-12-10 15:38:41
【问题描述】:
我正在使用 Beauitful Soup 框架来检索链接(来自以下 html 内容的引用)
<div class="store">
<label>Store</label>
<span>
<a title="Open in Google Play" href="https://play.google.com/store/apps/details?id=com.opera.mini.android" target="_blank">
<!-- ><span class="ui-icon app-store-gp"></span> -->
Google Play
</a><i class="icon-external-link"></i>
</span>
</div>
我使用以下代码在 python 中检索它:
pageFile = urllib.urlopen("appannie.com/apps/google-play/app/com.opera.mini.android")
pageHtml = pageFile.read()
pageFile.close()
print pageHtml
soup = BeautifulSoup("".join(pageHtml))
item = soup.find("a", {"title":"Open in Google Play"})
print item
我得到 NoneType 作为输出。任何帮助都会非常棒。
我打印了html页面,输出如下:
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body bgcolor="white">
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>nginx</center>
</body>
</html>
在浏览器上运行良好
【问题讨论】:
-
"503 Service Temporarily Unavailable" 所以这不是 BeautifulSoup 问题,而是服务器问题...您确定您请求的页面正确吗?尝试设置一个像您的浏览器一样的通用用户代理,看看它是否仍然可以。
标签: python html beautifulsoup href