我想獲取下載鏈接。例如,在http://www.brothersoft.com/windows/top-downloads/如何在使用beautifulsoup的python中獲得下載鏈接?
所以預期的結果應該是:
List of url:
1. http://www.brothersoft.com/photoscape-64604.html
2. http://www.brothersoft.com/orbit-downloader-54366.html
3. ....
4. ...
till 100.
我曾嘗試這樣的代碼:
import urllib
from bs4 import BeautifulSoup
pageFile = urllib.urlopen("http://www.brothersoft.com/windows/top-downloads/")
pageHtml = pageFile.read()
pageFile.close()
soup = BeautifulSoup("".join(pageHtml))
sAll = soup.findAll("a")
for i in range (0,100)
for link in sAll:
print i,link
但它給出不正確的輸出。 謝謝
我得到這個錯誤:文件 「C:\ Documents和Settings \法魯斯\桌面\ soup.py」,第13行,在 打印I,SALL [I] [ 「HREF」] 文件「C:\編碼 返回codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError:'charmap'編解碼器無法編碼字符u'\ u2013'在位置 115:「Python27 \ lib \ encodings \ cp437.py」字符映射到 –
那麼'print i,sAll [i] [「href」]。encode('utf-8')'? – 2013-08-21 02:50:17
文件「C:\ Documents and Settings \ Fairuz \ Desktop \ soup.py」,第13行,在 print i,sAll [i] [「href」] 文件「C:\ Python27 \ lib \ encodings \ cp437編碼 返回codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError:'charmap'編解碼器無法編碼字符u'\ u2013'在位置 115:字符映射到 –