java爬蟲報錯
阿新 • • 發佈:2020-12-21
java.lang.NumberFormatException: For input string: “”
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_221]
at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_221]
at java.lang.Long.parseLong(Long.java:631) ~[na:1.8.0_221]
at com.ccx.task.ItemTask.parse(ItemTask.java:61) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_221]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_221]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_221]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_221]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_221]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_221]
在練習爬蟲專案時出現了這個錯誤,經過除錯發現parselong裡面的引數不能為null
專案要獲得spu的值
但第一個spu為null,所以報錯
if ( "".equals(spuEle.attr("data-spu"))) {
continue;
}
只要過濾掉這個null就可以了