Skip to content

Commit

Permalink
requests类获取302后的内容
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetao Yang authored and Zetao Yang committed Jun 6, 2017
1 parent 22fae81 commit 0fb41ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
8 changes: 4 additions & 4 deletions core/phpspider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1327,10 +1327,10 @@ public function get_urls($html, $collect_url, $depth = 0)
//$urls = array();
//if (!empty($matchs[1]))
//{
//foreach ($matchs[1] as $url)
//{
//$urls[] = str_replace(array("\"", "'",'&'), array("",'','&'), $url);
//}
//foreach ($matchs[1] as $url)
//{
//$urls[] = str_replace(array("\"", "'",'&'), array("",'','&'), $url);
//}
//}

if (empty($urls))
Expand Down
31 changes: 11 additions & 20 deletions core/requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,9 @@ public static function set_cookies($cookies, $domain = '')

foreach ($cookies_arr as $cookie)
{
$cookie_arr = explode("=", $cookie);
$key = $value = "";
foreach ($cookie_arr as $k=>$v)
{
if ($k == 0)
{
$key = trim($v);
}
else
{
$value .= trim(str_replace('"', '', $v));
}
}
$key = strstr($cookie, '=', true);
$value = substr(strstr($cookie, '='), 1);
$cookie_arr = explode("=", $cookie, 2);
$key = $cookie_arr[0];
$value = empty($cookie_arr[1]) ? '' : $cookie_arr[1];

if (!empty($domain))
{
Expand Down Expand Up @@ -323,7 +311,7 @@ public static function get_response_cookies($domain)
$cookies = explode(";", $cookies);
foreach ($cookies as $cookie)
{
$cookie_arr = explode("=", $cookie);
$cookie_arr = explode("=", $cookie, 2);
// 过滤 httponly、secure
if (count($cookie_arr) < 2)
{
Expand All @@ -344,14 +332,14 @@ public static function get_response_cookies($domain)
}
}

public static function get_response_headers($html)
public static function get_response_headers($header)
{
$header_lines = explode("\n", $html);
$header_lines = explode("\n", $header);
if (!empty($header_lines))
{
foreach ($header_lines as $line)
{
$header_arr = explode(":", $line);
$header_arr = explode(":", $line, 2);
$key = empty($header_arr[0]) ? '' : trim($header_arr[0]);
$val = empty($header_arr[1]) ? '' : trim($header_arr[1]);
if (empty($key) || empty($val))
Expand Down Expand Up @@ -599,9 +587,12 @@ public static function request($url, $method = 'GET', $fields)

// header + body,header 里面有 cookie
curl_setopt( self::$ch, CURLOPT_HEADER, true );
// 返回最后的Location
curl_setopt( self::$ch, CURLOPT_FOLLOWLOCATION, true);

self::$raw = curl_exec ( self::$ch );
//var_dump($data);
// 真实url
//$location = curl_getinfo( self::$ch, CURLINFO_EFFECTIVE_URL);
self::$info = curl_getinfo( self::$ch );
self::$status_code = self::$info['http_code'];
if (self::$raw === false)
Expand Down
1 change: 1 addition & 0 deletions library/cls_redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static function init()
$prefix = empty($config['prefix']) ? self::$prefix : $config['prefix'];
self::$links[self::$link_name]->setOption(Redis::OPT_PREFIX, $prefix . ":");
self::$links[self::$link_name]->setOption(Redis::OPT_READ_TIMEOUT, -1);
self::$links[self::$link_name]->select($config['db']);
}

return self::$links[self::$link_name];
Expand Down

0 comments on commit 0fb41ab

Please sign in to comment.