我試圖抓取IMDB特色從高級職稱搜索頁面(http://www.imdb.com/search/title?count=250&title_type=feature&view=simple)薄膜多頁之後,這是我的代碼部分:得到錯誤顯示java.lang.NullPointerException爬行
for(int start=1; start < 295378; start+=250)
try {
String baseUrl = "http://www.imdb.com/search/title?start="+start+";count="+count+"&title_type=feature&view=simple";
org.jsoup.Connection con = Jsoup.connect(baseUrl).userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21");
con.timeout(30000).ignoreHttpErrors(true).followRedirects(true);
Response resp = con.execute();
Document doc = null;
if (resp.statusCode() == 200) {
doc = con.get();
Elements myElements = doc.getElementsByClass("results").first().getElementsByTag("table");
Elements trs = myElements.select(":not(thead) tr");
一切運作良好,直到編號100239我得到這個錯誤:
java.lang.NullPointerException
at featuredfilms.cinemamovies.main(cinemamovies.java:44)
該代碼仍然適用於從1號電影到100238,只是沒有工作後! 赦免如果這是明顯的事情,因爲我是新的爬網和Java。我很感激,如果有人親切地告訴我爲什麼我得到這個錯誤,我該如何解決它?
感謝,
什麼是第44行? – 2014-02-24 21:00:51
嘗試訪問未初始化的內容時拋出NullPointerException。檢查有什麼 –
像imdb這樣的網站通常不喜歡它被抓取。可能他們彈出了一種驗證碼頁面,以避免被輕易抓取。 – donfuxx