저는 9 개의 팝업 링크가있는 Page A를 가지고 있으며 각 팝업에서 정보를 추출해야합니다. 이 후에 나는 페이지 A로 돌아가서 계속 작업해야합니다.CasperJS - 페이지 위로 팝업 링크를 반복하고 모든 팝업을 긁은 후 페이지 A로 돌아갑니다.
for 루프에서 waitForPopup 및 withPopup을 사용했는데 각 팝업을 열고 닫는 올바른 방법이라고 생각합니다. 그러나 이상한 것은 내가 9 번 반복 된 첫 번째 팝업에서 정보를 얻었습니다. 나는 그것을 얻기 위해 밤새도록 노력했지만 붙어있었습니다. 아래 내 코드를 살펴보십시오. 감사.
업데이트 정확한 연결 상태를 발견했습니다.
1> The code is part of the var suite_1 = function() { ...my code... }
2> The regex /fulltext/ here is based on the popup links
(only the Gid value varies), like url=http://www.***.com/fulltext_form.aspx&Gid=788...
3> I also have some debug info.
[debug] [phantom] Mouse event 'mousedown' on selector: xpath selector: (//a[@class="main-ljwenzi"])[9]
[debug] [phantom] Mouse event 'mouseup' on selector: xpath selector: (//a[@class="main-ljwenzi"])[9]
[debug] [phantom] Mouse event 'click' on selector: xpath selector: (//a[@class="main-ljwenzi"])[9]
[debug] [phantom] Navigation requested: url=http://www.***.com/fulltext_form.aspx&Gid=788, type=LinkClicked, willNavigate=true, isMainFrame=false
: 내 스크립트 내부
Casperjs - Is ThenClick Or Any 'then Function' Synchronized Function?
, while 루프가, 내 스크립트가 당신의 내용은 thenClick
전에 While 루프의 끝으로 이동합니다 발견
... 그리고 ...
[info] [phantom] Step anonymous 119/122 http://www.***.com/fulltext_form.aspx&Gid=252923 (HTTP 200)
The program is expected to open the link with Gid=788, but after some _step, it still open the Gid=252923, which is the first popup.
HTML (popup.html) : 10 코드
this.then(function() {
var count = this.getElementsInfo('a.main').length;
this.echo(count + ' fulltext links found:', 'INFO');
for (var i = 1; i < count + 1; i++) {
//According to the output,
the program will run the this.capture 9 times,
before run the following lines of code 9 times
this.capture('before the click - ' + i + '.png');
this.thenClick(x('(//a[@class="main"])[' + i + ']'));
this.waitForPopup(/fulltext/, function() {
this.echo('Popup opened', 'INFO');
this.echo(this.getTitle(), 'INFO');
}, null, 10000);
this.withPopup(/fulltext/, function() {
this.echo(this.getTitle(), 'INFO');
this.waitForSelector('#tbl_content_main', function() {
// do something
});
});
this.then(function() {
this.echo('Back to the main page' + this.getTitle(), 'INFO_BAR');
});
}
});
안녕하세요 Sayakiss, 그때 함수에서 코드를 래핑하려고했지만 실패했습니다. Xpath selector : (// a [@ class = "main-ljwenzi"]) [10]', 왜냐하면 단지 9 개의 링크가 있기 때문입니다. for 루프가 단순히 9 번 실행 된 다음 코드의 클릭 부분을 실행 한 것처럼 보였습니다. 내 코드는 약 200 행입니다. 코드를 전자 메일로 보낼 수 있습니까? – user5404480
@ user5404480 전체 스크립트를 업로드 하시겠습니까? 요점 같은 것이 좋을 것입니다 ... – Sayakiss
1. 팝업에 집중하고 다른 웹 사이트에 간단한 스크립트를 작성할 수 있습니다 (그러나 문제를 재현 할 수 있음). 2. 게으른 사람이라면, 내 이메일 : zhushuierjirou @ gmail.com에 코드를 보낼 수 있습니다. – Sayakiss