为了账号安全,请及时绑定邮箱和手机立即绑定

报错could not be imported, invalid character,求解非常感谢!

# -*- coding: utf-8 -*-
class HtmlOutputer(object):
    def __init__(self):
        self.datas = []
        
    def collect_data(self, data):
        if data is None:
            return
        self.datas.append(data)
            
    
    def output_html(self):
        fout = open('output.html', 'w')
        
        fout.write('<html>')
        fout.write('<body>')
        fout.write('<table>')
        for data in self.datas:
            fout.write('<tr>')
            fout.write('<td>%s</td>'%data['url'].encode())
            fout.write('<td>%s</td>'%data['title'].encode())
            fout.write('<td>%s</td>'%data['summary'].encode())
            fout.write('</tr>')
            
        fout.write('</table>')
        fout.write('</body>')
        fout.write('</html>')
        fout.close()

============================= ERRORS =============================

Traceback (most recent call last):

  File "C:\Users\Administrator\.p2\pool\plugins\org.python.pydev.core_6.3.3.201805051638\pysrc\_pydev_runfiles\pydev_runfiles.py", line 468, in __get_module_from_str

    mod = __import__(modname)

  File "D:\practice\mooc\src\baike_spider\spider_main.py", line 23

    if&#12288;count == 1000:

      &#12288;    ^

SyntaxError: invalid character in identifier

ERROR: Module: spider_main could not be imported (file: D:/practice/mooc/src/baike_spider/spider_main.py).


# -*- coding: utf-8 -*-
class HtmlOutputer(object):
    def __init__(self):
        self.datas = []
        
    def collect_data(self, data):
        if data is None:
            return
        self.datas.append(data)
            
    
    def output_html(self):
        fout = open('output.html', 'w')
        
        fout.write('<html>')
        fout.write('<body>')
        fout.write('<table>')
        for data in self.datas:
            fout.write('<tr>')
            fout.write('<td>%s</td>'%data['url'].encode())
            fout.write('<td>%s</td>'%data['title'].encode())
            fout.write('<td>%s</td>'%data['summary'].encode())
            fout.write('</tr>')
            
        fout.write('</table>')
        fout.write('</body>')
        fout.write('</html>')
        fout.close()

============================= ERRORS =============================

Traceback (most recent call last):

  File "C:\Users\Administrator\.p2\pool\plugins\org.python.pydev.core_6.3.3.201805051638\pysrc\_pydev_runfiles\pydev_runfiles.py", line 468, in __get_module_from_str

    mod = __import__(modname)

  File "D:\practice\mooc\src\baike_spider\html_parser.py", line 25

    title_node = soup.find('dd', class="lemmaWgt-lemmaTitle-title").find('h1')

                                     ^

SyntaxError: invalid syntax

ERROR: Module: html_parser could not be imported (file: D:/practice/mooc/src/baike_spider/html_parser.py).


# -*- coding: utf-8 -*-
class HtmlOutputer(object):
    def __init__(self):
        self.datas = []
        
    def collect_data(self, data):
        if data is None:
            return
        self.datas.append(data)
            
    
    def output_html(self):
        fout = open('output.html', 'w')
        
        fout.write('<html>')
        fout.write('<body>')
        fout.write('<table>')
        for data in self.datas:
            fout.write('<tr>')
            fout.write('<td>%s</td>'%data['url'].encode())
            fout.write('<td>%s</td>'%data['title'].encode())
            fout.write('<td>%s</td>'%data['summary'].encode())
            fout.write('</tr>')
            
        fout.write('</table>')
        fout.write('</body>')
        fout.write('</html>')
        fout.close()


============================= ERRORS =============================

Traceback (most recent call last):

  File "C:\Users\Administrator\.p2\pool\plugins\org.python.pydev.core_6.3.3.201805051638\pysrc\_pydev_runfiles\pydev_runfiles.py", line 468, in __get_module_from_str

    mod = __import__(modname)

  File "D:\practice\mooc\src\baike_spider\html_outputer.py", line 8

    if data == None&#65306;

                   ^

SyntaxError: invalid character in identifier

ERROR: Module: html_outputer could not be imported (file: D:/practice/mooc/src/baike_spider/html_outputer.py).





正在回答

1 回答

后来解决啦,我是python36,代码如下

https://github.com/leslierere/mooc_study

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Python开发简单爬虫
  • 参与学习       227670    人
  • 解答问题       1219    个

本教程带您解开python爬虫这门神奇技术的面纱

进入课程

报错could not be imported, invalid character,求解非常感谢!

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信