背景
1.直接打开了本地写好的一个php文件,点击运行,结果是,运行了,当前的,之前打开的Python项目:
之前一直都是,在本地建立的apache服务器的localhost中,去运行用Notepad++编写出来的PHP代码。
现在装了Aptana Studio 3,打算接着去试试,看看能否直接使用其去编写,运行,调试php代码。
1.直接打开了本地写好的一个php文件,点击运行,结果是,运行了,当前的,之前打开的Python项目:
所以,貌似没法直接运行。
2.所以再去重新创建一个php项目:
填写好对应的信息后,点击完成:
然后就可以生成对应的php项目了:
然后去新建一个文件,此处选择从模板中建立:
改为所需的代码:
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
40
41
42
|
<?php
/*
Function:
【记录】尝试在PHP中支持Proxy代理去实现网络抓取
Date: 2013-01-11
Author: Crifan
Contact: admin (at) crifan (dot) com
*/
//用Php检测代理IP是否可用
$daili
=
'190.147.98.147:80'
;
function
curl_string (
$url
,
$proxy
)
{
$user_agent
=
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh- CN; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 FirePHP/0.2.1"
;
$ch
= curl_init();
curl_setopt (
$ch
, CURLOPT_PROXY,
$proxy
);
curl_setopt (
$ch
, CURLOPT_URL,
$url
);
//设置要访问的IP
curl_setopt (
$ch
, CURLOPT_USERAGENT,
$user_agent
);
//模拟用户使用的浏览器
curl_setopt(
$ch
, CURLOPT_FOLLOWLOCATION, 1 );
// 使用自动跳转
curl_setopt (
$ch
, CURLOPT_AUTOREFERER, 1 );
// 自动设置Referer
curl_setopt (
$ch
, CURLOPT_COOKIEJAR,
'cookie.txt'
);
curl_setopt (
$ch
, CURLOPT_HEADER, 1);
curl_setopt (
$ch
, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt (
$ch
, CURLOPT_TIMEOUT, 5);
$result
= curl_exec(
$ch
);
preg_match(
"/百度一下/isU"
,
$result
,
$baidu_okk
);
if
(
$baidu_okk
[0]==
''
)
{
echo
'no'
;
}
else
{
echo
'ok'
;Txtdb_a(
'daili.txt'
,
$proxy
.
"\r\n"
);
//将合格的代理IP记录在文件中
}
curl_close(
$ch
);
return
$result
;
}
?>
|
然后去想办法运行。
3.折腾半天,暂时没搞定。
其中遇到一些错误,详见:
4.接着,又遇到另外的错误:
5.然后又遇到问题了。
6.另外,此处,确定当前的:
和
都是一样的,可以正常运行的。
只是路径不对。