爬虫基础知识(一)

1. URL

URL的格式由三部分组成:
第一部分是协议(或称为服务方式)。
第二部分是存有该资源的主机IP地址(有时也包括端口号)。
第三部分是主机资源的具体地址,如目录和文件名等。

阅读全文

Python之jsonrpc

服务端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# server
from http.server import BaseHTTPRequestHandler, HTTPServer
from jsonrpcserver import methods
@methods.add
def ping():
return('ping')
@methods.add
def hao():
return('hao')
@methods.add
def hello(name):
return('Hello, %s' % name)
@methods.add
def Sum(a, b):
return(a + b)
class TestHttpServer(BaseHTTPRequestHandler):
def do_POST(self):
# Process request
request = self.rfile.read(int(self.headers['Content-Length'])).decode()
response = methods.dispatch(request)
# Return response
self.send_response(response.http_status)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(str(response).encode())
if __name__ == '__main__':
HTTPServer(('localhost', 5000), TestHttpServer).serve_forever()

阅读全文

正向代理和反向代理

正向代理

我们常说的代理也就是只正向代理,正向代理的过程,它隐藏了真实的请求客户端,服务端不知道真实的客户端是谁,客户端请求的服务都被代理服务器代替来请求,某些科学上网工具扮演的就是典型的正向代理角色。用浏览器访问 http://www.google.com 时,被残忍的block,于是你可以在国外搭建一台代理服务器,让代理帮我去请求google.com,代理把请求返回的相应结构再返回给我.

阅读全文

Python爬虫总结

爬虫需要用到的工具

正则表达式
XPATH
beautifulsoup
requests
urllib
urllib2
scrapy

阅读全文

linux开机自启

Linux下终端执行自定义命令启动程序

在/usr/bin目录下一般会存放一个shell脚本,然后在终端输入该shell脚本的名字,就会在终端执行这个shell脚本.

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
# 搜索进程中touchpanel的进程数目,这里是为了保持脚本执行的单个实例
var=`ps -aux |grep "/usr/bin/touchpanel" |wc -l`
# 注意空格不能少
if [ $var -gt 3 ];then
exit
fi
cd /opt/touchpanel
sudo python3 main.py $@

阅读全文