qq_32114925 2016-11-30 02:07 采纳率: 12.5%
浏览 10105

Python抓取程序无法运行

-*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import requests as req
import pandas as pd
import matplotlib.pyplot as plt
import time
import re
url='http://wenshu.court.gov.cn/List/ListContent'
Index=1
SleepNum= 3
dates=[]
titles=[]
nums=[]
while (Index < 123):
my_headers={'User-Agent':'User-Agent:Mozilla/5.0(Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.95Safari/537.36 Core/1.50.1280.400',}
data={'Param':'全文检索:执行', 'Index': Index,'Page':'20','Order':'裁判日期',
'Direction':'asc'}

r=req.post(url,headers=my_headers, data = data)
raw=r.json()

pattern1= re.compile('"裁判日期":"(.*?)"',re.S)
date= re.findall(pattern1,raw)
pattern2= re.compile('"案号":"(.*?)"',re.S)
num= re.findall(pattern2,raw)
pattern3= re.compile('"案件名称":"(.*?)"',re.S)
title= re.findall(pattern3,raw)

dates+=date
titles+=title
nums+=num
time.sleep(SleepNum)
Index+= 1
df=pd.DataFrame({'时间':dates,'案号':nums, '案件名称':titles})
df.to_excel('E:\result.xlsx') 
console内容:
Python 2.7.11 |Anaconda 4.1.0 (64-bit)| (default, Jun 15 2016, 15:21:11) [MSC v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 4.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
runfile('C:/Users/xx/.spyder2/temp.py', wdir='C:/Users/xx/.spyder2')
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/xx/.spyder2/temp.py', wdir='C:/Users/xx/.spyder2')
File "D:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
execfile(filename, namespace)
File "D:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/xx/.spyder2/temp.py", line 50, in
df.to_excel('E:\result.xlsx')
File "D:\Anaconda2\lib\site-packages\pandas\core\frame.py", line 1427, in to_excel
excel_writer.save()
File "D:\Anaconda2\lib\site-packages\pandas\io\excel.py", line 1444, in save
return self.book.close()
File "D:\Anaconda2\lib\site-packages\xlsxwriter\workbook.py", line 297, in close
self._store_workbook()
File "D:\Anaconda2\lib\site-packages\xlsxwriter\workbook.py", line 605, in _store_workbook
xml_files = packager._create_package()
File "D:\Anaconda2\lib\site-packages\xlsxwriter\packager.py", line 139, in _create_package
self._write_shared_strings_file()
File "D:\Anaconda2\lib\site-packages\xlsxwriter\packager.py", line 286, in _write_shared_strings_file
sst._assemble_xml_file()
File "D:\Anaconda2\lib\site-packages\xlsxwriter\sharedstrings.py", line 53, in _assemble_xml_file
self._write_sst_strings()
File "D:\Anaconda2\lib\site-packages\xlsxwriter\sharedstrings.py", line 83, in _write_sst_strings
self._write_si(string)
File "D:\Anaconda2\lib\site-packages\xlsxwriter\sharedstrings.py", line 110, in _write_si
self._xml_si_element(string, attributes)
File "D:\Anaconda2\lib\site-packages\xlsxwriter\xmlwriter.py", line 122, in _xml_si_element
self.fh.write("""%s""" % (attr, string))
File "D:\Anaconda2\lib\codecs.py", line 706, in write
return self.writer.write(data)
File "D:\Anaconda2\lib\codecs.py", line 369, in write
data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 7: ordinal not in range(128)
runfile('C:/Users/xx/.spyder2/temp.py', wdir='C:/Users/xx/.spyder2')ERROR: execution aborted

  • 写回答

2条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上