自动点击按钮和网页抓取
Auto click button and web scraping
我试图从网页中获取一些数据,并将其放入数组(php或javascript)或数据库中。
该页面的链接为:https://pilotweb.nas.faa.gov/PilotWeb/
我的问题是,我希望系统本身按下"我同意"按钮,然后在位置字段中填写"LGGG"一词。然后推送"查看注释"以获得结果。
从结果中,我需要检索粗体和一些坐标的名称。
我尝试了"使用jQuery加载页面时自动点击按钮元素"链接中的说明,但没有成功。
任何建议都会有帮助!
我找到了问题的答案,并将其发布,以防其他人面临同样的问题。
您所需要的只是页面中的客户端PHP URL:http://php.net/manual/en/book.curl.php
我的案例代码是:
define("CURL_AGENT", "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
$c = curl_init();
curl_setopt_array($c, array(
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_USERAGENT => CURL_AGENT,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_COOKIEFILE => 'NULL',
CURLOPT_COOKIEJAR => 'NULL',
CURLOPT_FOLLOWLOCATION => 1,
//the link i want to retrieve data
CURLOPT_URL => 'https://pilotweb.nas.faa.gov/PilotWeb/',
CURLOPT_COOKIESESSION => 1
));
$resp = curl_exec($c);
//from source code i get what I need
$post = 'formatType=DOMESTIC&retrieveLocId=LGGG&reportType=REPORT&openItems=icaosHeader%2Cicaos%3AicaoHead%2Cicao%3ArightNavSec0%2CrightNavSecBorder0%3A&actionType=notamRetrievalByICAOs&submit=View+NOTAMs';
curl_setopt_array($c, array(
CURLOPT_POST => 1,
//the link of target page
CURLOPT_URL => 'https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs',
CURLOPT_POSTFIELDS => $post
));
$resp = curl_exec($c);
curl_close($c);
上面的代码创建了一个HTML文件,其中包含页面的结果。
如果您可以使用jQuery并在页面中注入代码,并且代码可以是jQuery,那么您需要的代码行如下:
$(function () {
// on ready check the href
if (window.location.href == 'https://pilotweb.nas.faa.gov/PilotWeb/') {
// if cookie does not exist --> push I Agree
if (document.cookie.match(/^.*PILOTWEB_DISCLAIMER=true$/) === null) {
$("button:contains('I Agree')").trigger('click');
}
// set text
$('textarea[name="retrieveLocId"]').text('LGGG');
// submit form
$('form[action="/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs"] input[value="View NOTAMs"]').trigger('click');
} else {
// on second page get the results
if (window.location.href == 'https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs') {
$('[id="notamRight"] span strong').each(function(index, element) {
var boldValue = $(this).text();
// save it
});
}
}
});
相关文章:
- 自动点击按钮和网页抓取
- Python/R中的网页抓取javascript
- 使用Python使用Javascript进行网页抓取
- Python 网页抓取 JavaScript 生成的内容
- 等待Javascript网页抓取功能完成,然后再运行下一页
- 网页抓取:自动单击按钮
- NodeJS网页抓取工具,用于受密码保护的网站
- 使用PhantomJS进行网页抓取
- 在 NodeJS 中使用 Cheerio 进行网页抓取
- 在 Python 网页抓取期间触发 JS 事件
- 在弹出窗口中分页和网页抓取的CasperJS步骤的动态数量
- 网页抓取基础知识
- R:网页抓取与JavaScript(需要给两个值和抓取表)
- Android登录应用程序使用网页抓取与后台WebView
- Nodejs网页抓取与认证cookie
- react-native ios中的网页抓取
- 从网页抓取中删除空白
标签nodejs - 在网页抓取中连字符转换成逗号
- 解决方案的服务器端网页抓取/导航(JavaScript支持)
- 使用jQuery从另一个网页抓取内容