问 题
新手,在学习python爬虫,环境是python3.4,想爬取人民日报评论员文章,现在只怕去了一个网页,代码如下,
import requests
from bs4 import BeautifulSoup
import re
myUrl = "http://cpc.people.com.cn/pinglun/n1/201/0613/c78779-28428425.html"
response = requests.get(myUrl)
soup = BeautifulSoup(response.text, "lxml", from_encoding="gbk")
print(soup.title.string.encode('ISO-8859-1').decode('gbk'))
for a in soup.find_all(style="text-indent: 2em;"):
print(a.string.encode('ISO-8859-1').decode('gbk'))
网页上出错的源代码如下:
《 人民日报 》( 2016年06月13日 01 版)
我的出错提示如下:
Traceback (most recent call last):
File "pa_chong_lx.py", line 21, in
print(a.string.encode('ISO-8859-1').de