Skip to content

Commit

Permalink
添加服务器获取接口更多筛选条件
Browse files Browse the repository at this point in the history
  • Loading branch information
awolfly9 committed Feb 20, 2017
1 parent 0b54674 commit 5886aca
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
58 changes: 36 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,18 @@ python 2.7.12
* scrapy
* BeautifulSoup
* requests
* mysql-connector-python
* mysql-connector-python [安装参考](http://stackoverflow.com/questions/31748278/how-do-you-install-mysql-connector-python-development-version-through-pip)
* web.py
* scrapydo
* lxml


###Mysql 配置

###安装 Mysql

* 安装 Mysql 并启动
* 安装 mysql-connector-python [安装参考](http://stackoverflow.com/questions/31748278/how-do-you-install-mysql-connector-python-development-version-through-pip)
3. 在 config.py 更改数据库配置

```
database_config = {
'host': 'localhost',
'port': 3306,
'user': 'root',
'password': '123456',
}
```


##下载使用
将项目克隆到本地
Expand All @@ -44,6 +36,20 @@ $ git clone https://github.com/awolfly9/IPProxyTool.git
```
$ cd IPProxyTool
```
修改 mysql 数据库配置 [config.py](https://github.com/awolfly9/IPProxyTool/blob/master/config.py) 中 database_config 的用户名和密码为数据库的用户名和密码

```
$ vim config.py
---------------
database_config = {
'host': 'localhost',
'port': 3306,
'user': 'root',
'password': '123456',
}
```


分别运行代理抓取、验证、服务器 脚本

Expand Down Expand Up @@ -98,7 +104,7 @@ $ python runspider.py
$ python runvalidator.py
```

###获取代理 ip 数据服务器
###获取代理 ip 数据服务器接口
在 config.py 中修改启动服务器端口配置 data_port,默认为 8000
启动服务器

Expand All @@ -108,13 +114,17 @@ $ python runserver.py

服务器提供接口
####获取
http://127.0.0.1:8000/select?name=douban
http://101.200.55.192:8000/select?name=douban&anonymity=1&https=yes&sort=speed&count=100

参数

| Name | Type | Description |
| ----| ---- | ---- |
| name | str | 数据库名称 |
| Name | Type | Description |是否必须|
| ----| ---- | ---- | --- |
| name | str | 数据库名称 ||
| anonymity | int | 1:高匿 2:匿名 3:透明 ||
| https | str | https:yes http:no ||
| sort | str | 排序依据,默认 speed 升序 ||
| count | int | 获取代理数量,默认 100 ||



Expand All @@ -124,10 +134,10 @@ http://127.0.0.1:8000/delete?name=free_ipproxy&ip=27.197.144.181

参数

| Name | Type | Description |
| ----| ---- | ---- |
| name | str | 数据库名称 |
| ip | str | 需要删除的 ip |
| Name | Type | Description | 是否必须|
| ----| ---- | ---- | --- |
| name | str | 数据库名称 ||
| ip | str | 需要删除的 ip ||

####插入
http://127.0.0.1:8000/insert?name=douban&ip=555.22.22.55&port=335&country=%E4%B8%AD%E5%9B%BD&anonymity=1&https=yes&speed=5&source=100
Expand All @@ -147,9 +157,9 @@ http://127.0.0.1:8000/insert?name=douban&ip=555.22.22.55&port=335&country=%E4%B8


##TODO
* 添加服务器获取接口更多筛选条件
* 添加抓取更多免费代理网站
* 分布式部署项目
* ~~添加服务器获取接口更多筛选条件~~
* ~~添加 https 支持~~
* ~~添加检测 ip 的匿名度~~

Expand All @@ -159,6 +169,10 @@ http://127.0.0.1:8000/insert?name=douban&ip=555.22.22.55&port=335&country=%E4%B8


##项目更新
-----------------------------2017-2-20----------------------------<br>
1.添加服务器获取接口更多筛选条件<br>
<br>

-----------------------------2017-2-16----------------------------<br>
1.验证代理 IP 的匿名度<br>
2.验证代理 IP HTTPS 支持<br>
Expand Down
19 changes: 18 additions & 1 deletion server/dataserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,24 @@ def GET(self):

inputs = web.input()
name = inputs.get('name')
command = "SELECT * FROM {0}".format(name)
anonymity = inputs.get('anonymity', None)
https = inputs.get('https', None)
sort = inputs.get('sort', 'speed')
count = inputs.get('count', 100)

command = ''
if anonymity is None and https is None:
command = "SELECT * FROM {0} ORDER BY {1} LIMIT {2}".format(name, sort, count)
elif anonymity is not None and https is None:
command = "SELECT * FROM {0} WHERE anonymity=\'{1}\' ORDER BY {2} LIMIT {3}". \
format(name, anonymity, sort, count)
elif anonymity is None and https is not None:
command = "SELECT * FROM {0} WHERE https=\'{1}\' ORDER BY {2} LIMIT {3}". \
format(name, https, sort, count)
elif anonymity is not None and https is not None:
command = "SELECT * FROM {0} WHERE anonymity=\'{1}\' AND https=\'{2}\' ORDER BY {3} limit {4}". \
format(name, anonymity, https, sort, count)

result = sql.query(command)
data = [{'ip': item[1], 'port': item[2], 'speed': item[6]} for item in result]
data = json.dumps(data, indent = 4)
Expand Down

0 comments on commit 5886aca

Please sign in to comment.