如何使用Python提交不立即返回结果的PHP表单?

2024-10-03 09:21:14 发布

您现在位置:Python中文网/ 问答频道 /正文

有一个PHP表单可以查询大量的数据库。表单的URL是https://db.slickbox.net/venues.php。在发送表单后,返回结果最多需要10分钟,结果在同一页内联返回。我尝试过使用Requests、URLLib2、LXML和Selenium,但是我没有找到使用这些库的解决方案。有人知道在提交此表单后检索结果的页面源的方法吗?你知道吗

如果您知道解决方案,为了测试,只需在名称字段(“vname”)中填写想到的任何商店/加油站的名称。最后,我还需要设置带有“checked”属性的复选框,但这是我工作之后的后续目标。谢谢您!你知道吗


Tags: https名称数据库url表单dbneturllib2
2条回答

我通常靠卷发来做这种事。 直接调用响应页面(给出您的请求),而不是发送带有检索源的按钮的表单。 因为我在PHP下工作,所以很容易做到这一点。使用python,您将需要pycURL来管理同样的事情。你知道吗

所以唯一要做的就是打电话场馆.php使用POST method with Curl抛出的好参数值。你知道吗

这样,您将需要准备您的请求(国家代码、猫名),但您不需要选中复选框,也不需要在浏览器上加载网站页面。你知道吗

set_ini(max_execution_time,1200) // wait 20 minutes before quitting
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://db.slickbox.net/venues.php");
curl_setopt($ch, CURLOPT_HEADER, 0);

// prepare arguments for the form
$data = array('adlock   ' => 1, 'age' => 0,'country' => 145,'imgcnt'=>0, 'lock'=>0,'regex'=>1,'submit'=>'Search','vname'=>'test');

//add arguments to our request
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//launch request
if( ! $result = curl_exec($ch))
{
    trigger_error(curl_error($ch));
} 
echo $result;

ghost呢?你知道吗

from ghost import Ghost
ghost = Ghost()

with ghost.start() as session:
    page, extra_resources = session.open("https://db.slickbox.net/venues.php", wait_onload_event=True)
    ghost.set_field_value("input[name=vname]", "....")
    # Any other values
    page.fire_on('form', 'submit')
    page, resources = ghost.wait_for_page_loaded()

    content = session.content # or page.content I forgot which

在您可以使用beautifulsoup来解析HTML或Ghost之后,可能会有一些基本的实用程序来完成这项工作。你知道吗

相关问题 更多 >