python - Python 脚本在本地运行,但不在 Ubuntu 服务器上运行
问题描述
这是我在这个论坛上的第一篇文章,我希望以正确的方式解释我的问题。
所以我写了这个小的网络爬虫来更新我在亚马逊上的产品价格更新价格。之后,它会在 Telegram 上向我发送通知。
def check_price():
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id='priceblock_ourprice').get_text() # this is the problematic line
converted_price = title[0:6]
converted_price = float(converted_price.replace(',', '.'))
if os.path.exists('data.txt'):
with open('data.txt', 'r+') as f:
f_contents = f.read()
if converted_price != float(f_contents):
send_msg('The price was updated to: ' + str(converted_price) + '€')
f.write(str(converted_price))
else:
send_msg('The price was updated to: ' + str(converted_price) + '€')
with open('data.txt', 'w') as f:
f.write(str(converted_price))
return
现在的问题是它可以在我的本地机器上运行并且我收到了通知。但是当我尝试在服务器上运行代码时,我收到以下消息:
Traceback (most recent call last):
File "main.py", line 44, in <module>
check_price()
File "main.py", line 16, in check_price
title = soup.find(id='priceblock_ourprice').get_text()
AttributeError: 'NoneType' object has no attribute 'get_text'
我只是发布用于检查价格而不是发送的主要功能,因为问题发生在此之前。我无法以我的方式找到错误。我希望你能帮助我,谢谢。
解决方案
推荐阅读
- javascript - 将 Laravel 路由参数传递给 JavaScript
- entity-framework - 我可以使用 Azure AD 连接用户模拟 EF 吗?
- c# - 使用 ML.Net 进行多类分类的置信度
- spring-integration - Spring集成-来自sftp入站的聚合器
- r - 为日期解析重复正则表达式模式
- php - 从时差使用的分钟,甚至是 php 中一分钟的一小部分
- python - 在 json 中使用递归
- emacs - 为 Emacs 键绑定定义属性(文档字符串)
- jquery - jquery 3.3.1 Uncaught TypeError: e.indexOf is not a function at w.fn.init.w.fn.load
- ldap - nexus ldap config,验证用户映射成功,验证登录错误