Set page status code for SeleniumDownloader. Fixes #1185

pull/1186/head
Joe Zhou 1 month ago
parent 9bb2417f58
commit b1cf7ae455

@ -6,6 +6,7 @@ import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Request; import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Task; import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.selector.PlainText; import us.codecraft.webmagic.selector.PlainText;
import us.codecraft.webmagic.utils.HttpConstant;
import java.io.*; import java.io.*;
@ -96,7 +97,7 @@ public class PhantomJSDownloader extends AbstractDownloader {
page.setRawText(content); page.setRawText(content);
page.setUrl(new PlainText(request.getUrl())); page.setUrl(new PlainText(request.getUrl()));
page.setRequest(request); page.setRequest(request);
page.setStatusCode(200); page.setStatusCode(HttpConstant.StatusCode.CODE_200);
} }
onSuccess(page, task); onSuccess(page, task);
} catch (Exception e) { } catch (Exception e) {

@ -14,9 +14,11 @@ import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.downloader.AbstractDownloader; import us.codecraft.webmagic.downloader.AbstractDownloader;
import us.codecraft.webmagic.selector.Html; import us.codecraft.webmagic.selector.Html;
import us.codecraft.webmagic.selector.PlainText; import us.codecraft.webmagic.selector.PlainText;
import us.codecraft.webmagic.utils.HttpConstant;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.net.http.HttpRequest;
import java.util.Map; import java.util.Map;
/** /**
@ -111,6 +113,7 @@ public class SeleniumDownloader extends AbstractDownloader implements Closeable
page.setHtml(new Html(content, request.getUrl())); page.setHtml(new Html(content, request.getUrl()));
page.setUrl(new PlainText(request.getUrl())); page.setUrl(new PlainText(request.getUrl()));
page.setRequest(request); page.setRequest(request);
page.setStatusCode(HttpConstant.StatusCode.CODE_200);
onSuccess(page, task); onSuccess(page, task);
} catch (Exception e) { } catch (Exception e) {
logger.warn("download page {} error", request.getUrl(), e); logger.warn("download page {} error", request.getUrl(), e);

Loading…
Cancel
Save