我想获取下载链接。例如,在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:字符映射到 –