我试图将此抓取代码放在 AWS Lambda 上,当我尝试测试代码时,出现以下错误:
"errorMessage": "Unable to import module 'lambda_function': No module named 'lambda_function'",
"errorType": "Runtime.ImportModuleError"
代码:
from datetime import datetime
from functions import MultiplePageScraper, CleanTable, upload_unique, pages
from sqlalchemy import create_engine
now = datetime.now()
date = now.date()
# Credentials:
host = xxxxx
user = "admin"
password = xxxxx
port = 3306
database = "vehicles"
# Create connection
mydb = create_engine("mysql+pymysql://" + user + ':' + password + '@' + host + ':' + str(port) + '/' + database , echo=False)
# Target Url :
URL = "https://www.usedcars.co.ke/nairobi/cars-for-sale?page="
def lambda_handler(event, context):
# Retrive the data and clean it
page_count = pages(URL)
data = MultiplePageScraper(URL, int(page_count))
clean_data = CleanTable(data)
# Check for duplicates scraped Vs Database
upload_data = upload_unique(clean_data, mydb)
# Upload data to RDS database
if upload_data.shape[0] > 1:
upload_data.to_sql(name='CARS', con=mydb, if_exists = 'append', index=False)
print(f'Uploaded {upload_data.shape[0]} unique rows to the database!')
else:
print('No new cars to upload.')
我不知道这个错误意味着什么,有人可以帮忙吗?
最佳答案
关于python - 将代码上传到AWS lambda错误Runtime.ImportModuleError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66734570/