意图:工作流通过脚本节点抓取www.jin10.com的资讯,给到大模型做进一步资讯加工。
情况:在Window本地python上执行代码成功了,不过代码带有bs4,脚本节点不支持,改用了requests库代码,输出结果一直都是"scriptResult": {}
求解:问题是出在哪里?应该怎么写才成功?
以下是截图、电脑本地成功运行的代码和脚本节点的代码。
window电脑命令提示符运行成功的python文件代码:
import requests
import re
def extract_info_from_jin10():
url = "https://www.jin10.com"
try:
response = requests.get(url)
response.encoding = 'utf-8'
# 提取时间
time_pattern = re.compile(r'<div data-v-0bb4ed06="" class="item-time">(.*?)</div>')
time_match = time_pattern.search(response.text)
time = time_match.group(1).strip() if time_match else None
# 提取标题
title_pattern = re.compile(r'<b data-v-0bb4ed06="" class="right-common-title">(.*?)</b>')
title_match = title_pattern.search(response.text)
title = title_match.group(1).strip() if title_match else None
# 提取内容
content_pattern = re.compile(r'<div.*?class="flash-text">(.*?)</div>', re.DOTALL)
content_match = content_pattern.search(response.text)
content = content_match.group(1).strip() if content_match else None
return time, title, content
except Exception as e:
print(f"发生错误:{e}")
return None, None, None
if name == "main":
print("开始执行脚本")
time, title, content = extract_info_from_jin10()
if time and title and content:
print(f"时间:{time}\n标题:{title}\n内容:{content}")
else:
print("未成功提取信息。")
以下是工作流脚本节点的代码:
def extract_time_from_jin10():
url = "https://www.jin10.com"
try:
response = requests.get(url)
response.encoding = 'utf-8'
time_pattern = re.compile(r'
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。