import requests
import json
url = 'https://www.ptpress.com.cn/newsInfo/getCurrentAffairsForPortal'
return_data = requests.get(url).text
data = json.loads(return_data)
news = data['data']
for n in news:
picPath=n['picPath']
mainTitle= n['mainTitle']
newsContent = n['newsContent']
print("来源:",newsContent,'\n',"标题:",mainTitle,'\n',"图片:",picPath)
print('\n')
import requests
import json
url = 'http://www.ptpress.com.cn/bookinfo/getBookListForWS'
return_data = requests.get(url).text # 在需要爬取的URL网页进行HTTP请求
data = json.loads(return_data) # 对HTTP响应的数据JSON化
news = data['data'] # 索引到需要爬取的内容信息
for n in news: # 对索引出来的JSON数据进行遍历和提取
newsContent = n['newsContent']
mainTitle = n['mainTitle']
price = n['price']
print("新书名:",bookName,'\n',"作者:",author,'\n',"价格:",price)
print('\n')
请问为什么最下面的可以爬出出来,而上面的爬取不出来 报错了
请问怎样修改上面的代码才可以爬取出来呢?
谢谢