Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

爬取百度百科需要耗时100多秒,请问怎么解决 #1160

Open
yidasanqian opened this issue Apr 15, 2024 · 0 comments
Open

爬取百度百科需要耗时100多秒,请问怎么解决 #1160

yidasanqian opened this issue Apr 15, 2024 · 0 comments

Comments

@yidasanqian
Copy link

yidasanqian commented Apr 15, 2024

日志:
image

代码:

public class SpiderTest {

    private PhantomJSDownloader downloader;

    @BeforeEach
    public void setUp() {
        String osName = System.getProperty("os.name").toLowerCase();
        String phantomjsDriverPath = "/data/webdriver/phantomjs/";
        if (osName.contains("win")) {
            downloader = new PhantomJSDownloader(phantomjsDriverPath + "phantomjs.exe --ignore-ssl-errors=yes", phantomjsDriverPath + "crawl.js");
        } else {
            downloader = new PhantomJSDownloader(phantomjsDriverPath + "phantomjs --ignore-ssl-errors=yes", phantomjsDriverPath + "crawl.js");
        }
    }

    @Test
    public void testSpider() {
        long start = System.currentTimeMillis();
        List<WebPageResult> webPageResults = new ArrayList<>();
        WebPageResult webPageResult = new WebPageResult();
        webPageResult.setNo(0);
        webPageResult.setUrl("https://baike.baidu.com/item/2023%E5%B9%B410%E6%9C%88%E5%B7%B4%E4%BB%A5%E5%86%B2%E7%AA%81/63565377");
        webPageResults.add(webPageResult);
        ResultItems resultItems = Spider.create(new WebPageProcessor(webPageResults))
                .setDownloader(downloader)
                .get(webPageResult.getUrl());
        long end = System.currentTimeMillis();
        long cost = (end - start) / 1000;
        System.out.println("SpiderTest.testSpider cost: " + cost + "s");
    }
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant