我目前正在使用Behat和Mink&Goutte Driver.当我试图在我的开发环境中使用它时,通过app_dev.php
文件,这是Symfony2标准版的典型app_dev.php
文件,我的测试工作正常(Gists).
但是,如果我想使用一个app_test
文件(与app_dev
文件相同,除了环境参数设置为"test"而不是"dev",并禁用调试模式),在注销场景中,似乎Goutte可以找不到"user_signup"标识符,并且在"登录"方案中,它找不到"根"文本节点.事实上,当我使用a时print last response
,似乎用户还没有登录:我仍然看到用户登录表单...
当我在我的开发环境(app_dev
)或prod环境(app
)时,一切似乎都工作正常但是......任何想法?
(如果您认为需要其他文件,请告诉我).
问题:
无法完全理解Goutte网络刮刀.
请求:
有人可以帮助我理解或提供代码,以帮助我更好地了解如何使用Goutte网络刮刀吗?我已经阅读了README.md.我正在寻找比提供的更多信息,例如Goutte中可用的选项以及如何编写这些选项,或者当您查看表单时,您是否搜索表单的名称=或id =?
试图抓取的网页布局:
步骤1:
网页有一个表单,有一个单选按钮,可以选择填写哪种表格(即名称或许可证).默认情况下,名称带有名字和姓氏文本框以及状态下拉菜单选择列表.如果选择Radio,则会有jQuery或JavaScript使First和Last Name文本框消失,并显示License文本框.
第2步:
成功提交表单后,它会将您带到一个包含多个链接的页面.我们可以进入其中一个来获取我们需要的信息.
第3步:
一旦我们成功点击链接,我们希望第三页包含我们正在寻找的数据,并且我们希望将该数据存储到php变量中.
提交错误信息:
如果提交了错误信息,则jQuery/Javascript返回"未找到记录"消息.与提交的页面相同.
注意:
首选方法是选择许可证单选按钮,填写许可证编号,选择状态,然后提交表单.我已经阅读了大量关于Goutte的帖子和博客以及其他项目,我无处可以找到Goutte可用的选项,如何找到这些信息或如果它存在的话如何使用这些信息.
我有以下代码,但它总是返回407
HTTP状态代码.
$url = 'http://whatismyip.org';
$client = new Client();
$options = array(
'proxy' => array(
'http' => 'tcp://@x.x.x.x:8010',
),
'auth' => array('d80fe9ebasab73d21a4', '', 'basic')
);
$crawler = $client->request('GET', $url, $options);
$status = $client->getResponse()->getStatus();
echo $status; // 407
Run Code Online (Sandbox Code Playgroud)
我正在使用Goutte和Guzzle 6.我开始尝试设置代理,setDefaultOption
但这种方法已被弃用.
我的用户名和空白密码肯定是正确的,因为它curl
在命令行上使用:
curl -U d80fe9ebasab73d21a4: -vx x.x.x.x:8010 http://whatismyip.org/
Run Code Online (Sandbox Code Playgroud)
我已经花了几个小时在这上面,我将不胜感激任何帮助!
I am using PHP 7.1.33
and "fabpot/goutte": "^3.2"
. My composer file looks like the following:
{
"name": "ubuntu/workspace",
"require": {
"fabpot/goutte": "^3.2"
},
"authors": [
{
"name": "admin",
"email": "admin@admin.com"
}
]
}
Run Code Online (Sandbox Code Playgroud)
I am trying to get details by a time range from a webpage but struggle how to pass the $crawler
-values to my final result array $res1Array
.
I tried the following:
<?php
require 'vendor/autoload.php';
use Goutte\Client;
use Symfony\Component\DomCrawler\Crawler;
/**
* Crawls Detail Calender
* Does …
Run Code Online (Sandbox Code Playgroud) 很多时候,当我们遇到问题时,我们会遇到使用Javascript生成页面上呈现的内容的问题,因此scrapy无法为其抓取(例如,ajax请求,jQuery)
我正在使用Goutte从UTF-8网站上搜索,Goutte内部使用Guzzle.该网站声明了UTF-8的元标记,因此:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Run Code Online (Sandbox Code Playgroud)
但是,内容类型标题是:
Content-Type: text/html
Run Code Online (Sandbox Code Playgroud)
并不是:
Content-Type: text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)
因此,当我刮,Goutte没有发现它是UTF-8,并且错误地抓取数据.远程站点不在我的控制之下,所以我无法解决问题!这是一组用于复制问题的脚本.一,刮刀:
<?php
require_once realpath(__DIR__ . '/..') . '/vendor/goutte/goutte.phar';
$url = 'http://crawler-tests.local/utf-8.php';
use Goutte\Client;
$client = new Client();
$crawler = $client->request('get', $url);
$text = $crawler->text();
echo 'Whole page: ' . $text . "\n";
Run Code Online (Sandbox Code Playgroud)
现在要放置在Web服务器上的测试页面:
<?php
// Correct
#header('Content-Type: text/html; charset=utf-8');
// Incorrect
header('Content-Type: text/html');
?>
<!DOCTYPE html>
<html>
<head>
<title>UTF-8 test</title>
<meta charset="utf-8" />
</head>
<body>
<p>When the Content-Header header is incomplete, the pound sign …
Run Code Online (Sandbox Code Playgroud) 我的网站上有 html ( http://testsite.com/test.php ):
<div class="first">
<div class="second">
<a href="/test.php">click</a>
<span>back</span>
</div>
</div>
<div class="first">
<div class="second">
<a href="/test.php">click</a>
<span>back</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想收到:
<div class="first">
<div class="second">
<a href="/test.php">click</a>
</div>
</div>
<div class="first">
<div class="second">
<a href="/test.php">click</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以我想删除跨度。我在 Symfony2 中使用 Goutte 基于http://symfony.com/doc/current/components/dom_crawler.html:
$client = new Client();
$crawler = $client->request('GET', 'http://testsite.com/test.php');
$crawler->filter('.first .second')->each(function ($node) {
//??????
});
Run Code Online (Sandbox Code Playgroud) 这是我的目标网站:http://www.rapid7.com/db/,我想在那里进行搜索,假设字符串“Symphony”来检查它的漏洞。
检查输入表单的元素,我发现它的名称是“q”,到目前为止还不错,但是按钮没有值,相反,我需要提交查询的按钮是:<span id="run_search" class="vbsearchBtn"></span>
没有值字段。
我的代码:
$client = new Client();
$crawler = $client->request('GET', 'http://www.rapid7.com/db/');
$form = $crawler->selectButton('????')->form();
$crawler = $client->submit($form, array('q' => 'Symphony'));
print $crawler->html();
Run Code Online (Sandbox Code Playgroud)
有谁知道如何执行此操作?
我正在使用 Goutte 制作网络爬虫。
为了进行开发,我保存了一个我想要遍历的 .html 文档(因此我不会不断向网站发出请求)。这是我到目前为止所拥有的:
use Goutte\Client;
$client = new Client();
$html=file_get_contents('test.html');
$crawler = $client->request(null,null,[],[],[],$html);
Run Code Online (Sandbox Code Playgroud)
据我所知,应该在 Symfony\Component\BrowserKit 中调用请求,并传入原始正文数据。这是我收到的错误消息:
PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\ConnectException' with message 'cURL error 7: Failed to connect to localhost port 80: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\Users\Ally\Sites\scrape\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.
Run Code Online (Sandbox Code Playgroud)
如果我只使用 DomCrawler,那么使用字符串创建爬虫并不简单。(参见: http: //symfony.com/doc/current/components/dom_crawler.html)。我只是不确定如何用 Goutte 做同样的事情。
提前致谢。
我在这里发现了类似的问题。但我没有获得足够的信息,所以我决定提出新问题。
我们假设 url 如下。
url1. http://base_url/login
url2. http://base_url/home
url3. http://base_url/target
Note: if I logged in url1, site redirects to url2 after login and
2 cookies are saved on browser(called CTID, CTP).
Run Code Online (Sandbox Code Playgroud)
我想废弃url3,但是登录后可以访问url3。
我是这样写程序的。
use Goutte\Client;
... ...
$client = new Client();
$client->setHeader('User-Agent', "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36");
$crawler = $client->request('GET', 'url1');
$form = $crawler->selectButton('LOGON')->form();
$crawler = $client->submit($form, array('ID' => '***', 'PASS' => '***'));
dump($crawler->html()); //1
$crawler = $client->request('GET', 'url3');
dump($crawler->html()); //2
Run Code Online (Sandbox Code Playgroud)
指令1正确输出了url2的结果。(这意味着登录成功。)但我无法获取url3的内容。我该如何获取url3的内容?感谢您阅读我的问题。
goutte ×10
php ×8
guzzle ×3
web-crawler ×3
web-scraping ×3
symfony ×2
behat ×1
dom ×1
domcrawler ×1
html ×1
laravel-5 ×1
mink ×1
scraper ×1
testing ×1