Php 从站点页面中删除内容
我遇到了一些问题,需要帮助 我的计划: 1.从免费代理获取ip(嗨,我的屁股) 2.转换为XMLPhp 从站点页面中删除内容,php,html,Php,Html,我遇到了一些问题,需要帮助 我的计划: 1.从免费代理获取ip(嗨,我的屁股) 2.转换为XML $html = file_get_contents('http://www.hidemyass.com/proxy-list/'); //$body = explode('<tbody>', $html); $body = $html; $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?>
$html = file_get_contents('http://www.hidemyass.com/proxy-list/');
//$body = explode('<tbody>', $html);
$body = $html;
$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><xml />");
$rows = array();
foreach (array_slice(explode('<td>', end($body)), 1) as $row)
{
preg_match('/span>([0-9])<\/span>/', $row, $ids);
preg_match('/span>([0-9])<\/span>/', $row, $dir);
preg_match('/span>([0-9])<\/span>/', $row, $due);
$node = $xml->addChild('train');
$node->addChild('route', $ids[1]);
$node->addChild('direction', $dir[1]);
$node->addChild('due', $due[1]);
}
header('Content-Type: text/xml');
echo $xml->asXML();
$html=file\u get\u contents('http://www.hidemyass.com/proxy-list/');
//$body=explode(“”,$html);
$body=$html;
$xml=simplexml\u load\u字符串(“”);
$rows=array();
foreach(数组_切片(分解(“”,结束($body)),1)为$row)
{
preg_match('/span>([0-9])/',$row,$id);
preg_match('/span>([0-9])/',$row,$dir);
预匹配('/span>([0-9])/',$row,$due);
$node=$xml->addChild('train');
$node->addChild('route',$id[1]);
$node->addChild('direction',$dir[1]);
$node->addChild('due',$due[1]);
}
标题('Content-Type:text/xml');
echo$xml->asXML();
但还是不能
你能帮我吗
谢谢
jk最简单和理想的解决方案应该是
simple\u html\u dom
请参见:
范例
include 'simple_html_dom.php';
$html = file_get_html('http://www.hidemyass.com/proxy-list/');
echo "<pre>";
foreach ( $html->find ( 'tr' ) as $element ) {
$ip = $element->find ( 'td', 1 );
$port = $element->find ( 'td', 2 );
$ip = getIP ( $ip );
// var_dump($element->xmltext);
echo " $ip : $port \n";
}
function getIP($obj) {
global $html;
$text = str_replace ( "div", "span", $obj->xmltext );
$text = explode ( "span", $text );
$ip = array ();
foreach ( $text as $value ) {
$value = trim ( $value );
$value = trim ( $value, "<" );
$value = trim ( $value, ">" );
$value = trim ( $value, "." );
if (empty ( $value ))
continue;
if (strpos ( $value, "display:none" )) {
continue;
}
if (strpos ( $value, ">" )) {
$value = "<" . $value . ">";
}
$value = strip_tags ( $value );
$value = trim ( $value, "." );
if (empty ( $value ))
continue;
$ip [] = $value;
}
if (is_array ( $ip )) {
return implode ( ".", $ip );
}
}
你能看到
吗?有时
一些瓦片使用整数类,比如class=51
,这也意味着无
我能找到一份疯狂的工作。。使用getIP
函数。。。。我希望这有帮助
输出示例
谢谢最简单、最理想的解决方案应该是
simple\u html\u dom
请参见:
范例
include 'simple_html_dom.php';
$html = file_get_html('http://www.hidemyass.com/proxy-list/');
echo "<pre>";
foreach ( $html->find ( 'tr' ) as $element ) {
$ip = $element->find ( 'td', 1 );
$port = $element->find ( 'td', 2 );
$ip = getIP ( $ip );
// var_dump($element->xmltext);
echo " $ip : $port \n";
}
function getIP($obj) {
global $html;
$text = str_replace ( "div", "span", $obj->xmltext );
$text = explode ( "span", $text );
$ip = array ();
foreach ( $text as $value ) {
$value = trim ( $value );
$value = trim ( $value, "<" );
$value = trim ( $value, ">" );
$value = trim ( $value, "." );
if (empty ( $value ))
continue;
if (strpos ( $value, "display:none" )) {
continue;
}
if (strpos ( $value, ">" )) {
$value = "<" . $value . ">";
}
$value = strip_tags ( $value );
$value = trim ( $value, "." );
if (empty ( $value ))
continue;
$ip [] = $value;
}
if (is_array ( $ip )) {
return implode ( ".", $ip );
}
}
你能看到
吗?有时
一些瓦片使用整数类,比如class=51
,这也意味着无
我能找到一份疯狂的工作。。使用getIP
函数。。。。我希望这有帮助
输出示例
谢谢不要使用正则表达式解析html。改用DOM.waw…感谢Marc的快速响应..我将了解..刚刚添加了完整的工作版本--不要使用正则表达式解析html。改用DOM。哇…谢谢Marc的快速响应。我会学到的。刚刚添加了一个完整的工作版本。正在解决问题。。我会尽快更新doneWOW>>>>>>>>>>>>>>>超级…非常感谢…我欠你的太多了,爸爸…我如何在论坛上回复你。我是这个论坛的新手。顺便说一句,非常感谢你随时欢迎。。。很惊讶没有人回应你的请求…@Baba不幸的是,它不再起作用了。如果你能更新它就太好了,你将是我的英雄!谢谢。@user2203703更简单,只需在
getIP
函数parse/([a-z0-9\]+)\{([a-z\:]+)\}/i
中使用simplexml\u load\u string
。我真的不想更新代码,因为我认为它是因为以下答案而更改的:)正在解决问题。。我会尽快更新doneWOW>>>>>>>>>>>>>>>超级…非常感谢…我欠你的太多了,爸爸…我如何在论坛上回复你。我是这个论坛的新手。顺便说一句,非常感谢你随时欢迎。。。很惊讶没有人回应你的请求…@Baba不幸的是,它不再起作用了。如果你能更新它就太好了,你将是我的英雄!谢谢。@user2203703更简单,只需在getIP
函数parse/([a-z0-9\]+)\{([a-z\:]+)\}/i
中使用simplexml\u load\u string
。我真的不想更新代码,因为我认为它是因为以下答案而更改的:)
IP address : Port
200.135.197.120 : 8080
96.46.7.194 : 80
217.26.14.18 : 3128
189.114.111.190 : 8080
202.51.107.37 : 8080
128.208.04.198 : 2124
221.133.238.138 : 8080
41.215.247.146 : 8080
140.113.216.134 : 3128
190.211.132.33 : 8080
117.34.92.43 : 3128
118.97.235.234 : 3128
85.248.141.245 : 3128
203.223.47.119 : 3128
200.48.213.82 : 8080
217.112.128.247 : 80
114.134.76.27 : 8080
78.45.134.10 : 3128
77.78.197.15 : 8080
189.44.226.66 : 3128
124.195.124.166 : 8080
190.39.128.219 : 8080
222.42.45.51 : 3128
195.138.76.136 : 3128
115.249.252.235 : 8080
222.124.152.18 : 8080
190.255.39.147 : 3128
189.22.138.162 : 8080
217.146.208.162 : 8080
203.143.18.1 : 8080
210.57.215.130 : 80
190.98.166.106 : 3128
200.5.226.74 : 80
187.6.254.19 : 3128
177.36.242.57 : 8080
41.133.101.242 : 8080
201.87.208.66 : 8080
41.67.20.91 : 8080
118.192.1.168 : 3128
41.75.201.146 : 3128
61.166.144.69 : 8080
200.238.98.234 : 3128
110.52.11.220 : 80
125.67.230.192 : 8080
94.228.35.219 : 80
64.85.181.45 : 8080
222.169.15.234 : 8080
113.106.194.220 : 80
119.82.239.50 : 8080
117.27.139.17 : 80