84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
使用flask想实现一个简单的功能,访问一个类似http://www.baidu.com的URL,然后获取URL的访问结果,展示在页面上,百度未果,新手求教!
认证高级PHP讲师
Jump directly to the URL you want. Taking other people’s web pages is suspected of infringement. I don’t understand the purpose of this requirement. Want to make a mirror website?
Don’t quite understand what you want to do? If you just want to access a simple web page, you can use urllib or something like that.
1. Write an input box on your page to obtain search keywords 2. Construct Baidu’s search url based on the value of your input 3. Splice urls
Example: input value = testThe spliced url is as follows: https://www.baidu.com/s?ie=ut...
It is recommended to install and use the request library
$ pip install requests
from flask import make_response import requests @app.route("/test") def test(): response = make_response() # 请求百度url并取得响应内容 r = requests.get('http://www.baidu.com') # 如要还原请求的headers response.headers.update(r.headers) # 输出请求百度得到的数据 response.data = r.text return response
import urllib2 response = urllib2.urlopen("http://www.baidu.com") # 传入一个URL,协议是HTTP协议 print response.read() # response对象有一个read方法,可以返回获取到的网页内容。
This blog has detailed instructions that you can read and make it easier to advance: http://cuiqingcai.com/947.html
Jump directly to the URL you want. Taking other people’s web pages is suspected of infringement. I don’t understand the purpose of this requirement. Want to make a mirror website?
Don’t quite understand what you want to do? If you just want to access a simple web page, you can use urllib or something like that.
1. Write an input box on your page to obtain search keywords
2. Construct Baidu’s search url based on the value of your input
3. Splice urls
Example:
input value = test
The spliced url is as follows:
https://www.baidu.com/s?ie=ut...
It is recommended to install and use the request library
This blog has detailed instructions that you can read and make it easier to advance: http://cuiqingcai.com/947.html