import requests
from bs4 import BeautifulSoup
res = requests.get('http://news.sina.com.cn/china/')
res.encoding = 'utf-8'
soup = BeautifulSoup(res.text,'html.parser')
for news in soup.select('.news-item'):
if len(news.select('h2')) > 0:
h2 = news.select('h2')[0].text
a = news.select('a')[0]['href']
time = news.select('.time')[0].text
print(time,h2,a)
pip install requests pip install BeautifulSoup4
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'x.ui'
#
# Created by: PyQt5 UI code generator 5.8.1
#
# WARNING! All changes made in this file will be lost!
import sys
import requests
from PyQt5 import QtCore, QtGui, QtWidgets
from bs4 import BeautifulSoup
class Ui_x(object):
def getNews():
res = requests.get('http://news.sina.com.cn/china/')
res.encoding = 'utf-8'
soup = BeautifulSoup(res.text,'html.parser')
title = []
for news in soup.select('.news-item'):
if len(news.select('h2')) > 0:
h2 = news.select('h2')[0].text
title.append(h2)
a = news.select('a')[0]['href']
time = news.select('.time')[0].text
return '\n'.join(title)
def setupUi(self, x):
x.setObjectName("x")
x.resize(841, 749)
self.timeEdit = QtWidgets.QTimeEdit(x)
self.timeEdit.setGeometry(QtCore.QRect(310, 10, 141, 31))
self.timeEdit.setObjectName("timeEdit")
self.dateEdit = QtWidgets.QDateEdit(x)
self.dateEdit.setGeometry(QtCore.QRect(100, 10, 191, 31))
self.dateEdit.setObjectName("dateEdit")
self.textBrowser = QtWidgets.QTextBrowser(x)
self.textBrowser.setGeometry(QtCore.QRect(60, 80, 701, 641))
self.textBrowser.setObjectName("textBrowser")
self.retranslateUi(x)
QtCore.QMetaObject.connectSlotsByName(x)
def retranslateUi(self, x):
_translate = QtCore.QCoreApplication.translate
x.setWindowTitle(_translate("x", "x"))
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_x()
ui.setupUi(Form)
Form.show()
ui.textBrowser.setText(Ui_x.getNews())
sys.exit(app.exec_())
pip install pyinstaller
Pyinstaller -w x.py
ImportError: No module named 'queue' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test.py", line 2, in <module> File "c:\users\hasee\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.__dict__) File "site-packages\requests\__init__.py", line 63, in <module> File "c:\users\hasee\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.__dict__) File "site-packages\requests\utils.py", line 24, in <module> File "c:\users\hasee\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.__dict__) File "site-packages\requests\_internal_utils.py", line 11, in <module> File "c:\users\hasee\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.__dict__) File "site-packages\requests\compat.py", line 11, in <module> File "c:\users\hasee\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.__dict__) File "site-packages\requests\packages\__init__.py", line 29, in <module> ImportError: No module named 'urllib3' Failed to execute script test
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有