1. 程式人生 > 其它 >java爬蟲報錯

java爬蟲報錯

技術標籤:javajava

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 com.ccx.task.ItemTask.itemTask(ItemTask.java:43) ~[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 java.lang.reflect.Method.invoke(Method.java:498) ~[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.Executors R u n n a b l e A d a p t e r . c a l l ( E x e c u t o r s . j a v a : 511 ) [ n a : 1.8. 0 2 21 ] a t j a v a . u t i l . c o n c u r r e n t . F u t u r e T a s k . r u n A n d R e s e t ( F u t u r e T a s k . j a v a : 308 ) [ n a : 1.8. 0 2 21 ] a t j a v a . u t i l . c o n c u r r e n t . S c h e d u l e d T h r e a d P o o l E x e c u t o r RunnableAdapter.call(Executors.java:511) [na:1.8.0_221] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_221] at java.util.concurrent.ScheduledThreadPoolExecutor RunnableAdapter.call(Executors.java:511)[na:1.8.0221]atjava.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)[na:1.8.0221]atjava.util.concurrent.ScheduledThreadPoolExecutorScheduledFutureTask.access 301 ( S c h e d u l e d T h r e a d P o o l E x e c u t o r . j a v a : 180 ) [ n a : 1.8. 0 2 21 ] a t j a v a . u t i l . c o n c u r r e n t . S c h e d u l e d T h r e a d P o o l E x e c u t o r 301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_221] at java.util.concurrent.ScheduledThreadPoolExecutor 301(ScheduledThreadPoolExecutor.java:180)[na:1.8.0221]atjava.util.concurrent.ScheduledThreadPoolExecutorScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_221]
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就可以了