1 Star 0 Fork 0

linlihong_000/python-web-lxml

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
start.py 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
linlihong_000 提交于 2022-08-19 16:13 . 清除多余信息
# -*- coding: utf-8 -*-
from re import search
import web
import getData
### Url mappings
urls = ("/", "Index",
"/search", "Search",
'/(js|css|img)/(.*)','static' )
### Templates
render = web.template.render("templates", base="base")
class static:
def GET(self, media, file):
try:
f = open(media+'/'+file, 'rb')
return f.read()
except:
return ''
class Index:
form = web.form.Form(
web.form.Textarea(
"content", web.form.notnull, rows=30, cols=80, description='', placeholder="请输入url列表,用换行分隔"
),
web.form.Button("查询")
# ,
# validators = [web.form.Validator("urls不能为空.", lambda i: i.content == "")]
)
def GET(self):
form=self.form
return render.index(form)
def POST(self):
# if form.d.content=="":
# raise web.seeother("/tip")
form = self.form()
if not form.validates():
return render.new(form)
# print(form.d.title)
web.setcookie('urls', form.d.content)
raise web.seeother("/search")
class Search:
def GET(self):
urls=web.cookies().get('urls')
# urlArr=urls.split(",")
urlArr=urls.split("\r\n")
print(urls)
# print(urlArr)
posts=[]
for url in urlArr:
# print(getData.getData(url))
result=getData.getData(url)
item={'url':url,'title':result[3],'answerCount':result[0],'numberBoard_itemValue1':result[1],'numberBoard_itemValue2':result[2]}
print(item)
posts.append(item)
print(posts)
return render.result(posts)
app = web.application(urls, globals())
if __name__ == "__main__":
app.run()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/linlihong_000/python-web-lxml.git
git@gitee.com:linlihong_000/python-web-lxml.git
linlihong_000
python-web-lxml
python-web-lxml
master

搜索帮助