#!/usr/bin/env python
def load(url, typ, val):
from lxml import etree
import requests
response = requests.get(str(url))
html = response.text
root = etree.fromstring(html)
sets = './/*[@' + typ + '="' + val + '"]'
return root.xpath(sets)[0].text
url = "https://qna.habr.com/"
typ = "class"
val = "service-description"
load(url, typ, val)
usr@Inspiron-5749:~/Development/Python$ python lxml-parser.py
Traceback (most recent call last):
File "lxml-parser.py", line 15, in <module>
load(url, typ, val)
File "lxml-parser.py", line 7, in load
root = etree.fromstring(html)
File "src/lxml/etree.pyx", line 3235, in lxml.etree.fromstring
File "src/lxml/parser.pxi", line 1876, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1757, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1068, in lxml.etree._BaseParser._parseUnicodeDoc
File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 640, in lxml.etree._raiseParseError
File "<string>", line 5
lxml.etree.XMLSyntaxError: Entity 'mdash' not defined, line 5, column 34
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKit import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(845, 629)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.widget = QWebView(self.centralwidget)
self.widget.setObjectName("widget")
self.gridLayout.addWidget(self.widget, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 845, 18))
self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
self.menu_2 = QtWidgets.QMenu(self.menubar)
self.menu_2.setObjectName("menu_2")
self.menu_3 = QtWidgets.QMenu(self.menubar)
self.menu_3.setObjectName("menu_3")
self.menu_4 = QtWidgets.QMenu(self.menubar)
self.menu_4.setObjectName("menu_4")
self.menu_5 = QtWidgets.QMenu(self.menubar)
self.menu_5.setObjectName("menu_5")
self.menu_6 = QtWidgets.QMenu(self.menubar)
self.menu_6.setObjectName("menu_6")
self.menu_7 = QtWidgets.QMenu(self.menubar)
self.menu_7.setObjectName("menu_7")
MainWindow.setMenuBar(self.menubar)
self.menubar.addAction(self.menu.menuAction())
self.menubar.addAction(self.menu_2.menuAction())
self.menubar.addAction(self.menu_3.menuAction())
self.menubar.addAction(self.menu_4.menuAction())
self.menubar.addAction(self.menu_5.menuAction())
self.menubar.addAction(self.menu_6.menuAction())
self.menubar.addAction(self.menu_7.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Admin Panel"))
self.menu.setTitle(_translate("MainWindow", "Сайт"))
self.menu_2.setTitle(_translate("MainWindow", "Система"))
self.menu_3.setTitle(_translate("MainWindow", "Пользователи"))
self.menu_4.setTitle(_translate("MainWindow", "Меню"))
self.menu_5.setTitle(_translate("MainWindow", "Материалы"))
self.menu_6.setTitle(_translate("MainWindow", "Компоненты"))
self.menu_7.setTitle(_translate("MainWindow", "Расширения"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.widget.load(QUrl("https://qna.habr.com/q/710903?e=8568065#answer_item_1525865"))
ui.widget.show()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
@media (max-width:767px){
.navbar-fixed-bottom,.navbar-fixed-top,.navbar-static-top{margin-left:-20px;margin-right:-20px}
.container-fluid{padding:0}
.........
}
@media (max-width:767px){
.dropdown-menu .menuitem-group{background-color:#10223e;color:#eee}
.dl-horizontal dd,.row,.thumbnails{margin-left:0}
.........
}
@media (max-width:767px){
.navbar-fixed-bottom,.navbar-fixed-top,.navbar-static-top{margin-left:-20px;margin-right:-20px}
.container-fluid{padding:0}
.dropdown-menu .menuitem-group{background-color:#10223e;color:#eee}
.dl-horizontal dd,.row,.thumbnails{margin-left:0}
.........
}