【发布时间】:2017-02-26 12:51:28
【问题描述】:
运行时出现错误。
import requests
from bs4 import BeautifulSoup
url = "http://sport.citifmonline.com/"
url_page_2 = "url" + "2016/10/15/chelsea-3-0-leicester-city-dominant-blues-comfortable-against-champions-photos/"
r = requests.get(url)
soup = BeautifulSoup(r.content, "html5lib")
links = soup.find_all("a")
for link in links:
print "<a href='%s'>%s</a>" %(link.get("href"), link.text)
g_data = soup.find_all("div", {"class": "wrapper"})
for item in g_data:
articles = item.content[0].find_all("a", {"class": "cat-box-content"})[0].text
try:
print item.contents[1].find_all("h3", {"class": "post-box-title"})[0].text
except:
pass
【问题讨论】:
-
什么错误?请发布回溯。
-
不是每个人都愿意或能够运行你的代码;但是,如果您准确地说明您遇到了什么错误并描述您已经尝试做些什么来解决问题,那么有些人可能仍然能够提供帮助。
-
文件 "
",第 2 行打印 "%s" %(link.get("href"), link.text) ^ IndentationError: 期望缩进块@Daniel -
在我修复缩进错误后,我得到了这个 Traceback(最近一次调用最后):文件“
”,第 2 行,在 文件“C:\Python27\lib\encodings\ cp850.py",第 12 行,编码返回 codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019' in position 103: character maps to @Daniel
标签: python beautifulsoup html-parsing