在线抓取网页(flaskrestful,可以用的是osgi,环境配置())
优采云 发布时间: 2022-01-10 00:07在线抓取网页(flaskrestful,可以用的是osgi,环境配置())
在线抓取网页内容的selenium库。
flaskrestful框架如果你用的是osgi,可以用flask-osgi
环境配置如下:1.在命令行下输入pipinstallsocket-lib和socket-dev,然后回车,pipinstallsocket-apisocket-sequel,pipinstallsocket-torrent-python,然后回车,2.flask后运行socket服务,通过端口号我给它命名为python22,然后再flask中调用就可以,如下:importsocketimporthttpsocketfromdatetimeimportdatetimefromflask_rest_framework.rest_utilsimportrequest,request_accessfromflask_framework.utilsimportaccess_control,error_code#根据位置获取文件和端口号client=socket.builder()#找到文件,并添加为对象参数r=socket.routing(socket.broadcast(socket.state_basic_route(''),socket.state_basic_route('/')),socket.state_basic_route('/settings/blog/'))client.add_header("host","root")#获取所有链接(source)client.add_header("user-agent","mozilla/5.0(windowsnt6.1;wow64)applewebkit/537.36(khtml,likegecko)chrome/63.0.3272.132safari/537.36")#做一个简单的数据请求。
r=socket.request('get',access_control_error="waiting",headers={'accept':'application/json,text/javascript,*/*;q=0.01','accept-language':'zh-cn,zh;q=0.8','connection':'keep-alive','host':""})r.send(session.connect(socket.gethost(),socket.socket(host="")))#发送http请求print(client.receive(session.connect(socket.gethost(),host="")))。