【发布时间】:2017-07-25 05:57:12
【问题描述】:
这是我要爬的网站(http://biz.chosun.com/svc/list_in/list.html?catid=1A&pn=1),我的问题是爬完第一页后如何进入下一页。在这个网站页面源中,它没有显示最大页面,但我发现它可以达到7000。
这是我尝试但失败的代码。
【问题讨论】:
标签: c# selenium web-scraping web-crawler
这是我要爬的网站(http://biz.chosun.com/svc/list_in/list.html?catid=1A&pn=1),我的问题是爬完第一页后如何进入下一页。在这个网站页面源中,它没有显示最大页面,但我发现它可以达到7000。
这是我尝试但失败的代码。
【问题讨论】:
标签: c# selenium web-scraping web-crawler
您可以做的是检查当前网址。当您单击下一步按钮时,网址会更改。
第 1 页的网址 - http://biz.chosun.com/svc/list_in/list.html?catid=1A&pn=0
第 2 页的 URL - http://biz.chosun.com/svc/list_in/list.html?catid=1A&pn=2
假设您在最后一页并尝试单击下一个按钮,它将为您提供相同的 URL。
所以,你应该编写如下代码:
String current_URL = driver.getCurrentUrl();
String previous_URL = null;
while (current_URL != previous_URL)
{
// perform operations;
previous_URL = driver.getCurrentUrl();
// click on next;
current_URL = driver.getCurrentUrl();
}
【讨论】: