Я очень плохо знаком с языком Python и имею небольшую программу. Это работало, но что-то изменилось, и теперь я не могу заставить его работать. У него проблема с поиском 'pyodb c'. Я установил пакет 'pyodb c', поэтому не понимаю, почему произошла ошибка. Я использую Python 3.7.6. Спасибо за вашу помощь!
pip install pyodb c
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Requirement already satisfied: pyodbc in c:\users\c113850\appdata\roaming\python\python37\site-packages (4.0.28)
Код:
import requests
import pyodbc
from bs4 import BeautifulSoup
from datetime import datetime
import pytz
import time
import azure.functions
page = requests.get("https://samplepage.html")
if page.status_code == 200:
print(page.status_code)
#print(page.content)
soup = BeautifulSoup(page.content, 'html.parser')
print(soup.title)
rows = soup.find_all('tr')
# for row in rows: # Print all occurrences
# print(row.get_text())
print(rows[0])
print(rows[7])
pjmtime = rows[0].td.get_text()
print("PJM = ",pjmtime)
#dt_string = "Tue Jan 21 18:00:00 EST 2020"
dt_object = datetime.strptime(pjmtime, "%a %b %d %H:%M:%S EST %Y")
print("Timestamp =", dt_object)
eastern=pytz.timezone('US/Eastern')
date_eastern=eastern.localize(dt_object,is_dst=None)
date_utc=date_eastern.astimezone(pytz.utc)
print("UTC =", date_utc)
row = soup.find(text='PRICE').parent.parent
name = row.select('td')[0].get_text()
typed = row.select('td')[1].get_text()
weighted = row.select('td')[2].get_text()
hourly = row.select('td')[3].get_text()
server = 'db.database.windows.net'
database = '...'
username = '...'
password = '...'
driver = '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
print("insert into [PJMLocationalMarginalPrice] ([Name],[Type],[WeightedAverage],[HourlyIntegrated],[TimeStamp]) values(?,?,?,?,?)",
(name,typed,weighted,hourly,date_utc))
cursor.execute("insert into [PJMLocationalMarginalPrice] ([Name],[Type],[WeightedAverage],[HourlyIntegrated],[TimeStamp]) values (?,?,?,?,?)",
(name,typed,weighted,hourly,date_utc))
cnxn.commit()
else:
print("Error: page not open")
Ошибка:
Traceback (most recent call last):
File "c:/Users/C113850/PycharmProjects/Scraping101/Scraping.py", line 2, in <module>
import pyodbc
ImportError: DLL load failed: The specified module could not be found.
Обновление: я просматривал папки в пакетах сайта и заметил, что папки 'pyodb c' нет, но есть 'pyodb c -4.0 Папка .28.dist-info 'есть. ![enter image description here](https://i.stack.imgur.com/wXnrH.png)