# file\_get\_contents 设置代理抓取页面

#### `普通页面获取` <a href="#pu-tong-ye-mian-huo-qu" id="pu-tong-ye-mian-huo-qu"></a>

```
$url = "http://www.epooll.com/archives/806/";
$contents = file_get_contents($url);
preg_match_all("/<h1>(.*?)</h1>/is", $content, $matchs);
print_r($matchs[0]);
```

#### `设置代理IP去采集数据` <a href="#she-zhi-dai-li-ip-qu-cai-ji-shu-ju" id="she-zhi-dai-li-ip-qu-cai-ji-shu-ju"></a>

```
$context = array( 
    'http' => array( 
        'proxy' => 'tcp://192.168.0.2:3128',  //这里设置你要使用的代理ip及端口号 
        'request_fulluri' => true, 
    ), 
); 
$context = stream_context_create($context); 
$html = file_get_contents("http://www.epooll.com/archives/806/", false, $context); 
echo $html;
```

#### `设置需要验证的代理IP去采集数据` <a href="#she-zhi-xu-yao-yan-zheng-de-dai-li-ip-qu-cai-ji-shu-ju" id="she-zhi-xu-yao-yan-zheng-de-dai-li-ip-qu-cai-ji-shu-ju"></a>

```
$auth = base64_encode('USER:PASS');   //LOGIN:PASSWORD 这里是代理服务器的账户名及密码 
$context = array( 
    'http' => array( 
        'proxy' => 'tcp://192.168.0.2:3128',  //这里设置你要使用的代理ip及端口号 
        'request_fulluri' => true, 
        'header' => "Proxy-Authorization: Basic $auth",
    ), 
); 
$context = stream_context_create($context); 
$html = file_get_contents("http://www.epooll.com/archives/806/", false, $context); 
echo $html;
```

### results matching ""

*

### No results matching ""


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zhai-shi-sansorganization.gitbook.io/phpspider/filegetcontents-she-zhi-dai-li-zhua-qu-ye-mian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
