BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / python / #9948同步于 2015/11/21
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖

为什么同样的代码,不通的机器运行出来结果不一样啊?

spiritme
2015/11/21镜像同步13 回复
#-*-coding:utf-8-*- import requests import re import sys from bs4 import BeautifulSoup reload(sys) sys.setdefaultencoding("utf-8") #加载模块 hea = {'User-Agent':', 'cookie':''} html = ) #通过网站登录 User-Agent及cookie获取html soup = BeautifulSoup(html.text) K=soup.find_all("tbody") soup1 = BeautifulSoup(str(K)) P=soup1.get_text() Q=re.findall("\xe6\x80\xbb\xe7\xa8\x8e\xe9\xa2\x9d\xef\xbc\x9a(.*)",str(soup1)) #获取订单信息 file_object = open('thefile.txt', 'w') file_object.write(P) file_object.close( ) file_object = open('thefile.txt', 'a') file_object.write(str(Q)) file_object.close( ) #保存文件 print u'运行完成' 代码如上,在家里电脑运行完好,在公司电脑输出 D:\工具\Python\python.exe F:/PythonX/smarttb/test.py D:\工具\Python\lib\site-packages\beautifulsoup4-4.4.1-py2.7.egg\bs4\__init__.py:166: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently. To get rid of this warning, change this: BeautifulSoup([your markup]) to this: BeautifulSoup([your markup], "html.parser") 并且保存的内容中文没有正常显示,求大神指点
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
nuanyangyang机器人#1 · 2015/11/21
可以帮我翻译一下电脑的输出吗?
trouvan机器人#2 · 2015/11/21
哈哈,不是说程序员都忽略警告的么 【 在 spiritme (spirit) 的大作中提到: 】 : #-*-coding:utf-8-*- : import requests : import re : ................... 通过『我邮2.0』发布
mjy5800机器人#3 · 2015/11/21
两台机器的beautifulsoup版本是不是不一样啊?我猜测工作的机器版本更高些。 出现的warning是想说你应该自己指定一个解释器,否则这段代码可能在不同的环境下使用不同的解释器,导致结果不同。就按他提示的,选一个合适的解释器吧~ 发自「贵邮」
Dijkstraaaaa机器人#4 · 2015/11/22
输出已经很明显的指示出来了……
icybee机器人#5 · 2015/11/22
又是一个在windows上跑python的
dfxyz机器人#6 · 2015/11/22
忽略Warning的程序员都不是好程序员 【 在 trouvan 的大作中提到: 】 : 哈哈,不是说程序员都忽略警告的么 : : 通过『我邮2.0』发布
zoolsher机器人#7 · 2015/11/22
Dr.X 你好! 【 在 Dijkstraaaaa 的大作中提到: 】 : 输出已经很明显的指示出来了……
paper777机器人#8 · 2015/11/22
你的问题里自带答案了呃
Dijkstraaaaa机器人#9 · 2015/11/23
擦 【 在 zoolsher 的大作中提到: 】 : Dr.X 你好! : 【 在 Dijkstraaaaa 的大作中提到: 】 : : 输出已经很明显的指示出来了…… : :