Ekşisözlük Entry Alıcısı yaptım hata alıyorum!

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
from bs4 import BeautifulSoup 
import requests 


class Pencere(QWidget):
    def __init__(self):
        super().__init__()

        self.vLayout = QVBoxLayout(self)
        self.hLayout = QHBoxLayout(self)

        self.başlık = QLabel(self)
        self.başlık.setText("Ekşisözlük Entry Alıcı")
        self.başlık.setFont(QFont("Helvetica",25,QFont.Bold))
        self.başlık.setAlignment(Qt.AlignCenter)

        self.açıklamaLabel = QLabel(self)
        self.açıklamaLabel.setText("Link: ")

        self.logo = QLabel(self)
        self.logo.setPixmap(QPixmap("C:\\Users\\Asus\\Desktop\\ekşi.png"))
        self.logo.setAlignment(Qt.AlignCenter)

        self.textKutusu = QTextEdit(self)
        self.textKutusu.setFont(QFont("Helvetica",10,QFont.Bold))

        self.entry = QLineEdit(self)
        self.entry.setFont(QFont("Helvetica",10,QFont.Bold))

        self.gitButonu = QPushButton(self)
        self.gitButonu.setText("Git")
        self.gitButonu.setFont(QFont("Helvetica",10,QFont.Bold))

        self.vLayout.addWidget(self.başlık)
        self.vLayout.addWidget(self.logo)
        self.vLayout.addWidget(self.textKutusu)

        self.hLayout.addWidget(self.açıklamaLabel)
        self.hLayout.addWidget(self.entry)
        self.hLayout.addWidget(self.gitButonu)

        self.vLayout.addLayout(self.hLayout)

        self.gitButonu.clicked.connect(self.uygula)

    def uygula(self):
        print("çalıştı!")
        url = str(self.entry.text())
        print(url)

        r = requests.get(url) 
        print(r)
        soup = BeautifulSoup(r.content,"html.parser")


        liste = list()
        for i in soup.find_all("div",attrs={"class":"content"}):
            print(i.text)
            liste.append(i.text)

        toplamYazı = ""
        for i in liste:
            toplamYazı = toplamYazı + i + "\n"

        self.textKutusu.setText(toplamYazı)


app = QApplication(sys.argv)
window = Pencere()
window.show()
app.exec_()

def uygula(self):
kısmında print ( r ) yi kontrol için yazdım fakat konsola yazmıyor. Daha doğrusu program url yi konsola yazdıktan sonra ekran kapanıyor. Yardım edebilir misiniz?

Edeyim, gormedigin cikti su sekilde:

çalıştı!
https://eksisozluk.com/entry/11120716
Traceback (most recent call last):
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/tmp/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "a.py", line 55, in uygula
    r = requests.get(url)
  File "/tmp/venv/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/tmp/venv/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/tmp/venv/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/tmp/venv/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/tmp/venv/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Da ekranin kapanmasi ne demek? Nasil bir ekran o, hatani duzeltmek icin isine yarayacak bilgiyi gostermeden kapaniyor? Yeni ekran edinmen lazim.

Bu arada exception bilgileri stdout'a degil stderr'e gider. Ekran ayarlarin stderr'i gostermeyecek sekildeyse duzelt.

Evet hata göstermeden kapanıyor. Sizin hata olarak aldığınız çıktıyı ben almıyorum. Birde stderr ayarını nasıl yapabilirim?

Bilmem?

Bilgisayar mi kullaniyosun yoksa kodu arkadasina yollayip ciktisini posta yoluyla mi aliyosun? Eger ikincisiyse arkadasindan stderr'i de basmasini rica edebilirsin.

Nedenini bilmiyorum ama IDLE’da yazılmıyor (hatta Python’a restart atıyor). Terminalden açmak lazım.


Sorunun sebebi sitenin bot olduğunuzu anlayıp bağlantıyı kesmesi. User agenti değiştirmeniz yeterli, böylelikle sunucu bir tarayıcının kendisine istek yolladığını sanacak:

    def uygula(self):
        print(sys.stderr)
        print("çalıştı!")
        
        url = str(self.entry.text())
        print(url)
        r = requests.get(url, headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'})

        print(r)
        soup = BeautifulSoup(r.content,"html.parser")


        liste = list()
        for i in soup.find_all("div",attrs={"class":"content"}):
            print(i.text)
            liste.append(i.text)

        toplamYazı = ""
        for i in liste:
            toplamYazı = toplamYazı + i + "\n"

        self.textKutusu.setText(toplamYazı)
1 Beğeni

Cevabınız için teşekkür ederim.