Comments (6)
你好 @Ehco1996
- 关于POST请求请见 #106 ,对于发送ajax请求的data,目前解决是请先用data拼接好形成url再请求,或者自己构建route,然后定义视图函数自己构建,很灵活
- 对于第二点,不是很明白你的意思,想要获取h1下所有的文本(包括子标签)你是指获取html?
from toapi.
谢谢回复
-
post的data 和url没有关系吧,我的意思是不知道怎么 通过post方式获得items里的数据
-
第二点: 内置的XPath 方法返回的不是一个标准的 lxml 里的element对象,所以不能直接调用xpath内置的一些方法
from toapi.
你好 @Ehco1996
- #106 里面的post例子可以解决你的问题么?
- Xpath默认如果元素只有一个会返回text,如果你需要返回etree,可以使用内置的cssselect方式
from toapi.
谢谢回复!
第一问题我看到这样一个代码片段:
api = Api(url)
app = api.server.app
@app.route('/post_page/')
def post_method():
res = requests.post(url, data) # You need to analysis the ajax post request of source site.
return item.parse(res.text)
请问这段是需要加在app.py
里么?
我大概能看懂这是在flask里添加了一个post的路由
可是最后返回的 item.parse(res.text)
的item是从哪里来的呢?
还有这个路由是怎么和 Toapi Item
类发生联动的呢?
- 第二个问题解决了
再次感谢 !
from toapi.
你好 @Ehco1996
我将用下面的代码片段来解决你说的问题:
@api.server.app.route(/post_page/')
def post_page():
html = requests.post(url, data)
results = {}
# 定义一个Item列表,意思是你获取的html后,需要按照下面几个你自己定义的Item获取数据
items = [Item1,Item2]
for item in items:
parsed_item = api.parse_item(html, item['item'])
results[item].__name__] = parsed_item
return api.server.app.response_class(
response=json.dumps(results),
status=200,
mimetype='application/json'
)
明白了么?
from toapi.
@howie6879
明白了!太感谢了!
from toapi.
Related Issues (20)
- Add force-refresh on api HOT 1
- 使用toapi run 时出现问题 HOT 1
- 过滤删除无用的item
- Cache TTL clarification HOT 5
- Access to RawHTML from selectors HOT 2
- Production Deployment Instructions HOT 3
- python2.7安装报错 HOT 2
- How to set expiration on Local Storage
- toapi is easy toStar hard todevelope HOT 1
- Error: No such command "new". HOT 2
- ImportError: cannot import name 'XPath' HOT 2
- Flask logging error HOT 2
- SyntaxError: invalid syntax HOT 1
- modify routing argument 2
- Elements not always present on page
- Is this projects still active ?
- Problem: can't start the app
- Fix simple typo: programe -> program
- Your Documentation is unable to access HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toapi.