我使用Beauitful湯框架中檢索(從下面的html內容的href)的鏈接的Python 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服務暫時不可用」所以這不是BeautifulSoup問題,而是一個服務器...你確定你正在請求頁面正確嗎?嘗試設置一個像瀏覽器一樣的通用用戶代理,看看它是否仍然可以。 – 2013-11-25 19:18:15