S
S
Shamil Telekaev2019-04-19 19:04:40
Python
Shamil Telekaev, 2019-04-19 19:04:40

Why is data not being parsed from the local network, although the parsing works fine with the link to the site?

Hello, I'm a beginner in python'e and in general, in programming, please tell me why it's not possible to parse data using a link in the format http: //helpdesk.local.uralkali.com/maximo/ui/?event=loadapp&value=activity&uniqueid=397461&uisessionid =19831&csrftoken=qb7a7ob73gedm3h8erupgl2cec (there is a space in the link so that it does not shorten), but for a simple link, for example https://google.com/ , parsing works without errors. There are suggestions that the wrong libraries are being used, but I think it would be better to ask first. Test application code that was compiled to .exe and tested on a computer with a local network:

import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QLineEdit, QPushButton, QListWidget, QMessageBox
from PyQt5.QtCore import QSize
from bs4 import BeautifulSoup
import urllib.request

def get_html(url):
    response = urllib.request.urlopen(url)
    return response.read()

def parse_nomobr(html):
    global nomobr
    soup = BeautifulSoup(html, 'html5lib')
    for inp in soup.find_all('input', id='mx730'):
        nomobr = inp.get('value')

def parse_nomzak(html):
    global nomzak
    soup = BeautifulSoup(html, 'html5lib')
    for div in soup.find_all('div', id='mx385_holder'):
        nomzak = div.label.text

def parse_datsoz(html):
    global datsoz
    soup = BeautifulSoup(html, 'html5lib')
    for tit in soup.find_all('input', id='mx548'):
        datsoz = tit.get('title').replace(u'Дата создания: ','')

def parse_krasro(html):
    global krasro
    soup = BeautifulSoup(html, 'html5lib')
    for tit in soup.find_all('input', id='mx556'):
        krasro = tit.get('title').replace(u'Крайний срок: ','')

def parse_danpol_opisan(html):
    global danpol
    global opisan
    danpol = ''
    soup = BeautifulSoup(html, 'html5lib')
    table = soup.find('body', class_='tundra')
    for tab in table.find_all('table', id='mx724'):
        for tr in tab.find_all('tr')[3:14]:
            for inp in tr.find_all('input'):
                qwe = inp.get('value')
                if danpol == '':
                    danpol = qwe
                else:
                    danpol = '''\
{}
{}'''.format(danpol, qwe)
        for tr in tab.find_all('tr')[15:16]:
            for inp in tr.find_all('input'):
                opisan = inp.get('value')

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(300, 400))
        self.setMaximumSize(QSize(300, 400))
        self.setWindowTitle("TEST")

        self.nameLabel = QLabel(self)
        self.nameLabel.setText('Введите URL:')
        self.line = QLineEdit(self)
        self.listWidget = QListWidget(self)
        self.button = QPushButton('ОК', self)
        self.button.setShortcut('Return')
        self.button.clicked.connect(self.on_click)

        self.button.move(80, 60)
        self.line.move(80, 20)
        self.line.resize(200, 32)
        self.nameLabel.move(10, 20)
        self.listWidget.move(10, 100)
        self.listWidget.resize(280, 270)
        self.button.resize(200, 32)

    def on_click(self):
        if self.line.text() == '':
            self.messagebox = QMessageBox.warning(self, 'Ошибка', "Ничего не введено!", QMessageBox.Ok)
        else:
            file = self.line.text()
            parse_nomobr(get_html(file))
            parse_nomzak(get_html(file))
            parse_datsoz(get_html(file))
            parse_krasro(get_html(file))
            parse_danpol_opisan(get_html(file))
            for dan in nomobr, nomzak, datsoz, krasro, danpol, opisan:
                self.listWidget.addItem(dan)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit( app.exec_() )

The fact is that I am doing an internship in production, and I myself cannot check the program on the computer where it will be used in the future, so I have to compile it into .exe and the head of the practice already checks it himself, but the .exe does not show errors, everything just crashes, if you don’t know how to fix the error, then tell me how to make an error debugger, i.e. so that in case of an error the program gives out what exactly is wrong (preferably not through try - except, except has too many values ​​​​for this).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlessandrIT, 2019-04-19
@AlessandrIT

The URL that you described in the title - are you sending a request to it? Actually, through requests, this is done like this.
Moreover, the url here is http: //helpdesk.local.uralkali.com/
Where data contains data fields. In your case, here

these
?event=loadapp&value=activity&uniqueid=397461&uisessionid=19831&csrftoken=qb7a7ob73gedm3h8erupgl2cec

PS Is it legal to transfer a token in such a defenseless way?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question