Python3
html页面出现乱码,解决方法:
1)打开文件时加上编码:
fout = open('output.html', 'w', encoding='utf-8')
2)视频中在写入标题和内容时加入了编码转换,去掉,不要加,直接这样写:
fout.write("<td>%s</td>" % data['title'])
html页面出现乱码,解决方法:
1)打开文件时加上编码:
fout = open('output.html', 'w', encoding='utf-8')
2)视频中在写入标题和内容时加入了编码转换,去掉,不要加,直接这样写:
fout.write("<td>%s</td>" % data['title'])
2018-04-28
第二条就没有了的朋友,是因为百度改规则了,你们老是去爬。
html_parser 找到这里,改成: links = soup.find_all('a', href=re.compile(r"/item/.*"))
就可以了。
html_parser 找到这里,改成: links = soup.find_all('a', href=re.compile(r"/item/.*"))
就可以了。
2018-04-24
File "E:/python_work/Spider/baike_spider/spider_main.py", line 35, in <module>
obj_spider.craw(root_url)
File "E:/python_work/Spider/baike_spider/spider_main.py", line 13, in craw
self.urls.add_new_url(root_url)
AttributeError: 'SpiderMain' object has no attribute 'urls'
obj_spider.craw(root_url)
File "E:/python_work/Spider/baike_spider/spider_main.py", line 13, in craw
self.urls.add_new_url(root_url)
AttributeError: 'SpiderMain' object has no attribute 'urls'
2018-04-23
首先肯定明磊大佬的说法。
即使去掉encoding:'uft-8'依然报错,参见:https://bytes.com/topic/python/answers/556312-lookuperror-unknown-encoding-utf-8-a。
f.write('<td>{0}</td>' .format(data['url']))
f.write('<td>{0}</td>' .format(data['title']))
f.write('<td>{0}</td>' .format(data['summary']))
即使去掉encoding:'uft-8'依然报错,参见:https://bytes.com/topic/python/answers/556312-lookuperror-unknown-encoding-utf-8-a。
f.write('<td>{0}</td>' .format(data['url']))
f.write('<td>{0}</td>' .format(data['title']))
f.write('<td>{0}</td>' .format(data['summary']))
2018-04-21