import requests
import pandas as pd
from openpyxl import Workbook
# Verileri çekmek için istek atıyoruz
url = 'https://b2b.domain.net/Search.aspx/SearchProduct'
data = {"query":"aranan kelime","page":1,"brandCode":"","minPrice":0,"maxPrice":0,"categories":[]}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=data, headers=headers)
# İstek başarılı ise verileri işlemeye başlıyoruz
if response.status_code == 200:
# JSON verisini Python sözlük yapısına dönüştürüyoruz
data = response.json()
# Sözlük yapısını pandas DataFrame yapısına dönüştürüyoruz
df = pd.DataFrame.from_dict(data["d"]["result"])
# Excel dosyası için bir Workbook nesnesi oluşturuyoruz
wb = Workbook()
# Aktif çalışma sayfasını seçiyoruz
ws = wb.active
# DataFrame verilerini Excel sayfasına yazıyoruz
for r in dataframe_to_rows(df, index=False, header=True):
ws.append(r)
# Excel dosyasını kaydediyoruz
wb.save('veri_data.xlsx')her hangi bir hata vermiyor ama kayıt da yapmıyor... sorun ne ola ki...!
Python sorun nedir anlamadım
23
●438
- 18-04-2023, 06:50:10
- 18-04-2023, 07:07:06kurulu olmayan pip install openpyxl buymuş kurdum ama herhangi bi şlem yapmıyor... dediğiniz gibi kayıt konumunu değiştirdim aynı sorun devam ediyor bi hatamız var ama nedir bilmiyorumJosephC adlı üyeden alıntı: mesajı görüntüle
- 18-04-2023, 07:12:12tam olarak hangi satırdan başlıyor bu kodJosephC adlı üyeden alıntı: mesajı görüntüle
- 18-04-2023, 07:13:39
import requests import pandas as pd from openpyxl import Workbook from openpyxl.utils.dataframe import dataframe_to_rows # Verileri çekmek için istek atıyoruz url = 'https://b2b.domain.net/Search.aspx/SearchProduct' data = {"query":"aranan kelime","page":1,"brandCode":"","minPrice":0,"maxPrice":0,"categories":[]} headers = {"Content-Type": "application/json"} response = requests.post(url, json=data, headers=headers) # İstek başarılı ise verileri işlemeye başlıyoruz if response.status_code == 200: # JSON verisini Python sözlük yapısına dönüştürüyoruz data = response.json() # Sözlük yapısını pandas DataFrame yapısına dönüştürüyoruz df = pd.DataFrame.from_dict(data["d"]["result"]) # Excel dosyası için bir Workbook nesnesi oluşturuyoruz wb = Workbook() # Aktif çalışma sayfasını seçiyoruz ws = wb.active # DataFrame verilerini Excel sayfasına yazıyoruz for r in dataframe_to_rows(df, index=False, header=True): ws.append(r) # Excel dosyasını kaydediyoruz wb.save('veri_data.xlsx')
oda olmasa kodun hepsini böyle değiştirin - 18-04-2023, 07:17:42verdiğiniz kodu komple denedim şu hatayı aldım
--------------------------------------------------------------------------- gaierror Traceback (most recent call last) ~\anaconda3\lib\site-packages\urllib3\connection.py in _new_conn(self) 173 ) --> 174 175 return conn ~\anaconda3\lib\site-packages\urllib3\util\connection.py in create_connection(address, timeout, source_address, socket_options) 71 sock.settimeout(timeout) ---> 72 if source_address: 73 sock.bind(source_address) ~\anaconda3\lib\socket.py in getaddrinfo(host, port, family, type, proto, flags) 917 addrlist = [] --> 918 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 919 af, socktype, proto, canonname, sa = res gaierror: [Errno 11004] getaddrinfo failed During handling of the above exception, another exception occurred: NewConnectionError Traceback (most recent call last) ~\anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 702 # Didn't get a connection from the pool, no need to clean up --> 703 clean_exit = True 704 release_this_conn = False ~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw) 385 raise --> 386 387 # conn.request() calls httplib.*.request, not the method in ~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _validate_conn(self, conn) ~\anaconda3\lib\site-packages\urllib3\connection.py in connect(self) 357 and default_ssl_context --> 358 and hasattr(context, "load_default_certs") 359 ): ~\anaconda3\lib\site-packages\urllib3\connection.py in _new_conn(self) 185 --> 186 def connect(self): 187 conn = self._new_conn() NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000000005D545B0>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed During handling of the above exception, another exception occurred: MaxRetryError Traceback (most recent call last) ~\anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 438 if not chunked: --> 439 resp = conn.urlopen( 440 method=request.method, ~\anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 784 response.drain_conn() --> 785 retries.sleep_for_retry(response) 786 log.debug("Redirecting %s -> %s", url, redirect_location) ~\anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace) MaxRetryError: HTTPSConnectionPool(host='b2b.domain.net', port=443): Max retries exceeded with url: /Search.aspx/SearchProduct (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000000005D545B0>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed')) During handling of the above exception, another exception occurred: ConnectionError Traceback (most recent call last) <ipython-input-23-b2e1ffe20166> in <module> 8 data = {"query":"aranan kelime","page":1,"brandCode":"","minPrice":0,"maxPrice":0,"categories":[]} 9 headers = {"Content-Type": "application/json"} ---> 10 response = requests.post(url, json=data, headers=headers) 11 12 # İstek başarılı ise verileri işlemeye başlıyoruz ~\anaconda3\lib\site-packages\requests\api.py in post(url, data, json, **kwargs) 117 """ 118 --> 119 return request('post', url, data=data, json=json, **kwargs) 120 121 ~\anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs) 59 # cases, and look like a memory leak in others. 60 with sessions.Session() as session: ---> 61 return session.request(method=method, url=url, **kwargs) 62 63 ~\anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 528 } 529 send_kwargs.update(settings) --> 530 resp = self.send(prep, **send_kwargs) 531 532 return resp ~\anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs) 641 642 # Send the request --> 643 r = adapter.send(request, **kwargs) 644 645 # Total elapsed time of the request (approximately) ~\anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 514 raise SSLError(e, request=request) 515 --> 516 raise ConnectionError(e, request=request) 517 518 except ClosedPoolError as e: ConnectionError: HTTPSConnectionPool(host='b2b.domain.net', port=443): Max retries exceeded with url: /Search.aspx/SearchProduct (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000000005D545B0>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed')) - 18-04-2023, 07:20:00ben böyle bir hata aldım
Exception has occurred: ConnectionError HTTPSConnectionPool(host='b2b.domain.net', port=443): Max retries exceeded with url: /Search.aspx/SearchProduct (Caused by NewConnectionError('<urllib3.connection.HTTPSConne ction object at 0x0000023A34B2B010>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')) socket.gaierror: [Errno 11001] getaddrinfo failed During handling of the above exception, another exception occurred: urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000023A34B2B010>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed During handling of the above exception, another exception occurred: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='b2b.domain.net', port=443): Max retries exceeded with url: /Search.aspx/SearchProduct (Caused by NewConnectionError('<urllib3.connection.HTTPSConne ction object at 0x0000023A34B2B010>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')) During handling of the above exception, another exception occurred: File "D:Chat-GBTsorun duzelt pythontest.py", line 10, in <module> response = requests.post(url, json=data, headers=headers) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='b2b.domain.net', port=443): Max retries exceeded with url: /Search.aspx/SearchProduct (Caused by NewConnectionError('<urllib3.connection.HTTPSConne ction object at 0x0000023A34B2B010>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')) ben böyle bir hata aldım