Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jgjk
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
任建宇
jgjk
Commits
73c604a2
提交
73c604a2
authored
8月 04, 2021
作者:
任建宇
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
shan
上级
29ae01b4
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
340 行增加
和
17 行删除
+340
-17
ShopCommodityMapper.java
...resource/bg/mapper/shopCommodity/ShopCommodityMapper.java
+1
-1
ShopCommoditySerivceImpl.java
...ce/bg/service/shopCommodity/ShopCommoditySerivceImpl.java
+339
-16
没有找到文件。
app/resource/src/main/java/com/zrqx/resource/bg/mapper/shopCommodity/ShopCommodityMapper.java
浏览文件 @
73c604a2
...
@@ -43,7 +43,7 @@ public interface ShopCommodityMapper extends BaseMapper<ShopCommodity> {
...
@@ -43,7 +43,7 @@ public interface ShopCommodityMapper extends BaseMapper<ShopCommodity> {
+
"#{id}"
+
"#{id}"
+
"</foreach>"
+
"</foreach>"
+
"</if>"
+
"</if>"
+
" ORDER BY (case when currentprice >=sellingprice then 2 else 1 end)asc, bookname desc"
+
" ORDER BY (case when currentprice >=sellingprice then 2 else 1 end)asc, bookname desc
,a.id
"
+
"</script>"
)
+
"</script>"
)
List
<
ShopCommodityVo
>
page
(
@Param
(
"form"
)
ShopCommodityForm
form
);
List
<
ShopCommodityVo
>
page
(
@Param
(
"form"
)
ShopCommodityForm
form
);
...
...
app/resource/src/main/java/com/zrqx/resource/bg/service/shopCommodity/ShopCommoditySerivceImpl.java
浏览文件 @
73c604a2
package
com
.
zrqx
.
resource
.
bg
.
service
.
shopCommodity
;
package
com
.
zrqx
.
resource
.
bg
.
service
.
shopCommodity
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.PrintStream
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.Consts
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.ClientProtocolException
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.jsoup.Jsoup
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Element
;
import
org.jsoup.nodes.Element
;
...
@@ -15,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -15,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zrqx.core.enums.ResponseCodeEnum
;
import
com.zrqx.core.enums.ResponseCodeEnum
;
import
com.zrqx.core.exception.BaseException
;
import
com.zrqx.core.exception.BaseException
;
...
@@ -76,7 +89,8 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
...
@@ -76,7 +89,8 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
if
(
shop
.
getPlatform
().
equals
(
"当当1"
))
{
if
(
shop
.
getPlatform
().
equals
(
"当当1"
))
{
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
for
(
Commodity
commdoity
:
listCommdoity
)
{
for
(
Commodity
commdoity
:
listCommdoity
)
{
String
url
=
"http://shop.dangdang.com/14937/list.html?key="
+
commdoity
.
getIsbn
();
String
url
=
shop
.
getUrlWebsite
()
+
"/list.html?key="
+
commdoity
.
getIsbn
();
try
{
try
{
Document
doc
=
Jsoup
.
parse
(
new
URL
(
url
),
300000
);
Document
doc
=
Jsoup
.
parse
(
new
URL
(
url
),
300000
);
// 图书信息
// 图书信息
...
@@ -96,17 +110,18 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
...
@@ -96,17 +110,18 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
// 获取标题
// 获取标题
String
title
=
element
.
getElementsByTag
(
"a"
).
attr
(
"title"
);
String
title
=
element
.
getElementsByTag
(
"a"
).
attr
(
"title"
);
if
(
title
.
contains
(
commdoity
.
getIsbn
()))
{
if
(
title
.
contains
(
commdoity
.
getIsbn
()))
{
// 获取价格
// 获取价格
String
price
=
element
.
getElementsByClass
(
"preis"
).
text
();
String
price
=
element
.
getElementsByClass
(
"preis"
).
text
();
Example
example
=
this
.
createExample
();
Example
example
=
this
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
()).
andEqualTo
(
"shopId"
,
shop
.
getId
());
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
())
.
andEqualTo
(
"shopId"
,
shop
.
getId
());
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
BigDecimal
price1
=
new
BigDecimal
(
price
.
substring
(
1
,
price
.
length
()));
BigDecimal
price1
=
new
BigDecimal
(
price
.
substring
(
1
,
price
.
length
()));
shopCommodity
.
setCurrentprice
(
price1
);
shopCommodity
.
setCurrentprice
(
price1
);
if
(
listShop
.
size
()
>
0
)
{
if
(
listShop
.
size
()
>
0
)
{
//
修改售价
//
修改售价
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUpdateTime
(
new
Date
());
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
continue
;
continue
;
...
@@ -126,31 +141,238 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
...
@@ -126,31 +141,238 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
}
}
if
(
shop
.
getPlatform
().
equals
(
"蔚蓝"
))
{
if
(
shop
.
getPlatform
().
equals
(
"蔚蓝
1
"
))
{
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
for
(
Commodity
commdoity
:
listCommdoity
)
{
for
(
Commodity
commdoity
:
listCommdoity
)
{
String
url
=
"https://www.welan.com/search/ajax?keywords="
;
String
url
=
"https://www.welan.com/search/ajax?keywords="
;
String
result
=
HttpsUtils
.
sendGet
(
url
,
commdoity
.
getIsbn
());
String
result
=
HttpsUtils
.
sendGet
(
url
,
commdoity
.
getIsbn
());
JSONObject
object
=
(
JSONObject
)
JSON
.
parse
(
result
);
JSONObject
object
=
(
JSONObject
)
JSON
.
parse
(
result
);
//唯一标识用户的 openId
try
{
try
{
Thread
.
sleep
(
2000
);
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
e1
)
{
}
catch
(
InterruptedException
e1
)
{
// TODO Auto-generated catch block
// TODO Auto-generated catch block
e1
.
printStackTrace
();
e1
.
printStackTrace
();
}
}
if
(
Integer
.
parseInt
(
object
.
get
(
"dataCount"
).
toString
())
>
0
)
{
if
(
Integer
.
parseInt
(
object
.
get
(
"dataCount"
).
toString
())
>
0
)
{
System
.
out
.
println
();
System
.
out
.
println
();
if
(
commdoity
.
getIsbn
().
equals
(
object
.
getJSONArray
(
"books"
).
getJSONObject
(
0
).
get
(
"isbn"
)))
{
if
(
commdoity
.
getIsbn
().
equals
(
object
.
getJSONArray
(
"books"
).
getJSONObject
(
0
).
get
(
"isbn"
)))
{
Example
example
=
this
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
()).
andEqualTo
(
"shopId"
,
shop
.
getId
());
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
BigDecimal
price1
=
new
BigDecimal
(
object
.
getJSONArray
(
"books"
).
getJSONObject
(
0
).
get
(
"wlPrice"
).
toString
());
shopCommodity
.
setCurrentprice
(
price1
);
if
(
listShop
.
size
()
>
0
)
{
// 修改售价
shopCommodity
.
setUpdateTime
(
new
Date
());
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
continue
;
}
shopCommodity
.
setShopId
(
shop
.
getId
());
shopCommodity
.
setCommodityId
(
commdoity
.
getId
());
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUploadTime
(
new
Date
());
this
.
insert
(
shopCommodity
);
}
}
}
}
if
(
shop
.
getPlatform
().
equals
(
"文轩网1"
))
{
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
for
(
Commodity
commdoity
:
listCommdoity
)
{
String
url
=
"https://search.winxuan.com/search?keyword="
+
commdoity
.
getIsbn
();
try
{
Document
doc
=
Jsoup
.
parse
(
new
URL
(
url
),
300000
);
// 图书信息
Elements
elements
=
doc
.
getElementsByTag
(
"ul"
);
// System.out.println(elements);
Element
tempElement
=
null
;
for
(
Element
element
:
elements
)
{
if
(
element
.
className
().
equals
(
"group-ul"
))
{
tempElement
=
element
;
// System.out.println(element.className());
break
;
}
}
System
.
out
.
println
(
tempElement
);
Elements
li
=
tempElement
.
getElementsByTag
(
"li"
);
for
(
Element
element
:
li
)
{
// 获取标题
String
title
=
element
.
getElementsByTag
(
"a"
).
attr
(
"title"
);
// 获取价格
String
price
=
element
.
getElementsByClass
(
"price-n"
).
text
();
Example
example
=
this
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
()).
andEqualTo
(
"shopId"
,
shop
.
getId
());
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
BigDecimal
price1
=
new
BigDecimal
(
price
.
substring
(
1
,
price
.
length
()));
shopCommodity
.
setCurrentprice
(
price1
);
if
(
listShop
.
size
()
>
0
)
{
// 修改售价
shopCommodity
.
setUpdateTime
(
new
Date
());
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
continue
;
}
shopCommodity
.
setShopId
(
shop
.
getId
());
shopCommodity
.
setCommodityId
(
commdoity
.
getId
());
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUploadTime
(
new
Date
());
this
.
insert
(
shopCommodity
);
}
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
}
if
(
shop
.
getPlatform
().
equals
(
"孔夫子1"
))
{
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
for
(
Commodity
commdoity
:
listCommdoity
)
{
String
url
=
shop
.
getUrlWebsite
()
+
"/search/?key="
+
commdoity
.
getIsbn
();
try
{
Document
doc
=
Jsoup
.
parse
(
new
URL
(
url
),
300000
);
// 图书信息
Elements
elements
=
doc
.
select
(
"span[class=bold]"
);
if
(
elements
!=
null
)
{
for
(
Element
element
:
elements
)
{
// 获取价格
String
price
=
element
.
getElementsByClass
(
"bold"
).
text
();
Example
example
=
this
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
())
.
andEqualTo
(
"shopId"
,
shop
.
getId
());
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
BigDecimal
price1
=
new
BigDecimal
(
price
.
substring
(
1
,
price
.
length
()));
shopCommodity
.
setCurrentprice
(
price1
);
if
(
listShop
.
size
()
>
0
)
{
// 修改售价
shopCommodity
.
setUpdateTime
(
new
Date
());
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
continue
;
}
shopCommodity
.
setShopId
(
shop
.
getId
());
shopCommodity
.
setCommodityId
(
commdoity
.
getId
());
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUploadTime
(
new
Date
());
this
.
insert
(
shopCommodity
);
break
;
}
}
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
}
//爬取苏宁易购商品销售价格
if
(
shop
.
getPlatform
().
equals
(
"苏宁易购1"
))
{
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
for
(
Commodity
commdoity
:
listCommdoity
)
{
try
{
Document
doc
=
Jsoup
.
parse
(
new
URL
(
shop
.
getUrlWebsite
()),
300000
);
// 图书信息
Element
element
=
doc
.
getElementById
(
"CSupplierID"
);
// 获取商店信息ID
String
shopId
=
"00"
+
element
.
val
();
// 拼接接口路径
String
url
=
"https://csearch.suning.com/emall/cshop/queryByKeyword.do?vendor_Id="
+
shopId
+
"&keyword="
+
commdoity
.
getIsbn
()
+
"&start=0&rows=48&sortField=&cf=channel:PC,price:&pcode=11749307328&cityId=010&custno=&callback=jsonpQueryByKeyword"
;
String
result
=
HttpsUtils
.
sendGet
(
url
,
commdoity
.
getIsbn
());
System
.
out
.
println
(
result
);
result
=
result
.
substring
(
34
,
result
.
length
()-
2
);
JSONObject
object
=
(
JSONObject
)
JSON
.
parse
(
result
);
System
.
out
.
println
(
object
.
get
(
"goodsSize"
).
toString
());
//睡眠2秒
Thread
.
sleep
(
2000
);
if
(
Integer
.
parseInt
(
object
.
get
(
"goodsSize"
).
toString
())
>
0
)
{
JSONArray
jsonarry
=
object
.
getJSONArray
(
"goods"
);
for
(
int
i
=
0
;
i
<
jsonarry
.
size
();
i
++)
{
Example
example
=
this
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
())
.
andEqualTo
(
"shopId"
,
shop
.
getId
());
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
BigDecimal
price1
=
new
BigDecimal
(
jsonarry
.
getJSONObject
(
i
).
get
(
"price"
).
toString
());
shopCommodity
.
setCurrentprice
(
price1
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
));
if
(
listShop
.
size
()
>
0
)
{
// 修改售价
shopCommodity
.
setUpdateTime
(
new
Date
());
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
continue
;
}
shopCommodity
.
setShopId
(
shop
.
getId
());
shopCommodity
.
setCommodityId
(
commdoity
.
getId
());
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUploadTime
(
new
Date
());
this
.
insert
(
shopCommodity
);
}
}
}
catch
(
Exception
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
}
}
}
if
(
shop
.
getPlatform
().
equals
(
"网易考拉1"
))
{
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
for
(
Commodity
commdoity
:
listCommdoity
)
{
//睡眠2秒
String
url
=
shop
.
getUrlWebsite
();
String
shopid
=
null
;
if
(
url
.
contains
(
"pc"
))
{
shopid
=
url
.
substring
(
url
.
indexOf
(
"pc/"
)+
3
,
url
.
indexOf
(
"pc/"
)+
12
);
}
else
{
shopid
=
url
.
substring
(
url
.
indexOf
(
"kaola.com/"
)+
10
,
url
.
indexOf
(
"kaola.com/"
)+
19
);
}
url
=
"https://mall.kaola.com/search.html?shopId="
+
shopid
+
"&key="
+
commdoity
.
getIsbn
();
try
{
Thread
.
sleep
(
2000
);
Document
doc
=
Jsoup
.
parse
(
new
URL
(
url
),
300000
);
// 图书信息
Elements
elements
=
doc
.
getElementsByTag
(
"ul"
);
// System.out.println(elements);
Element
tempElement
=
null
;
for
(
Element
element
:
elements
)
{
if
(
element
.
className
().
equals
(
"clearfix"
))
{
tempElement
=
element
;
// System.out.println(element.className());
break
;
}
}
System
.
out
.
println
(
tempElement
);
Elements
li
=
tempElement
.
getElementsByTag
(
"li"
);
for
(
Element
element
:
li
)
{
// 获取价格
String
price
=
element
.
getElementsByClass
(
"cur"
).
text
();
Example
example
=
this
.
createExample
();
Example
example
=
this
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
()).
andEqualTo
(
"shopId"
,
shop
.
getId
());
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
()).
andEqualTo
(
"shopId"
,
shop
.
getId
());
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
BigDecimal
price1
=
new
BigDecimal
(
object
.
getJSONArray
(
"books"
).
getJSONObject
(
0
).
get
(
"wlPrice"
).
toString
(
));
BigDecimal
price1
=
new
BigDecimal
(
price
.
substring
(
1
,
price
.
length
()
));
shopCommodity
.
setCurrentprice
(
price1
);
shopCommodity
.
setCurrentprice
(
price1
);
if
(
listShop
.
size
()
>
0
)
{
if
(
listShop
.
size
()
>
0
)
{
//
修改售价
//
修改售价
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUpdateTime
(
new
Date
());
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
continue
;
continue
;
...
@@ -160,14 +382,115 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
...
@@ -160,14 +382,115 @@ public class ShopCommoditySerivceImpl extends BaseServiceImpl<ShopCommodity, Str
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUploadTime
(
new
Date
());
shopCommodity
.
setUploadTime
(
new
Date
());
this
.
insert
(
shopCommodity
);
this
.
insert
(
shopCommodity
);
}
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
}
}
}
}
if
(
shop
.
getPlatform
().
equals
(
"京东"
))
{
List
<
Commodity
>
listCommdoity
=
commodityService
.
selectAll
();
for
(
Commodity
commdoity
:
listCommdoity
)
{
// String url = shop.getUrlWebsite();
int
j
=
10
;
for
(
int
i
=
0
;
i
<
j
;
i
++)
{
String
input
=
commdoity
.
getIsbn
();
// 需要爬取商品信息的网站地址
String
url
=
"https://search.jd.com/Search?keyword="
+
input
+
"&enc=utf-8"
;
// 动态模拟请求数据
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
HttpGet
httpGet
=
new
HttpGet
(
url
);
// 模拟浏览器浏览(user-agent的值可以通过浏览器浏览,查看发出请求的头文件获取)
httpGet
.
setHeader
(
"user-agent"
,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
);
CloseableHttpResponse
response
=
null
;
try
{
Thread
.
sleep
(
5000
);
response
=
httpclient
.
execute
(
httpGet
);
// 获取响应状态码
int
statusCode
=
response
.
getStatusLine
().
getStatusCode
();
HttpEntity
entity
=
response
.
getEntity
();
// 如果状态响应码为200,则获取html实体内容或者json文件
if
(
statusCode
==
200
)
{
String
html
=
EntityUtils
.
toString
(
entity
,
Consts
.
UTF_8
);
// 提取HTML得到商品信息结果
Document
doc
=
Jsoup
.
parse
(
html
);
File
f
=
new
File
(
"D:\\out.txt"
);
f
.
createNewFile
();
FileOutputStream
fileOutputStream
=
new
FileOutputStream
(
f
);
PrintStream
printStream
=
new
PrintStream
(
fileOutputStream
);
System
.
setOut
(
printStream
);
System
.
out
.
println
(
"默认输出到控制台的这一句,输出到了文件 out.txt"
);
System
.
out
.
println
(
doc
);
// 通过浏览器查看商品页面的源代码,找到信息所在的div标签,再对其进行一步一步地解析,这都需要对html代码进行分析了
Elements
ulList
=
doc
.
select
(
"#J_goodsList"
);
Elements
liList
=
ulList
.
select
(
".gl-item"
);
Elements
fptex
=
doc
.
select
(
".fp-text"
);
System
.
out
.
println
(
fptex
.
text
());
if
(
StringUtils
.
isNotBlank
(
fptex
.
text
()))
{
String
text
=
fptex
.
text
().
substring
(
2
,
3
);
j
=
Integer
.
parseInt
(
text
);
System
.
out
.
println
(
"j进来玩"
+
j
);
}
// 循环liList的数据(具体获取的数据值还得看doc的页面源代码来获取,可能稍有变动)
for
(
Element
item
:
liList
)
{
// 商品价格
String
price
=
item
.
select
(
".p-price"
).
select
(
"i"
).
text
();
System
.
out
.
println
(
"商品价格:"
+
price
);
// 店铺url
String
shopUrl
=
item
.
select
(
".J_im_icon"
).
select
(
"a"
).
attr
(
"href"
);
//截取店铺、
String
shopUrlLocahost
=
shop
.
getUrlWebsite
().
substring
(
shop
.
getUrlWebsite
().
indexOf
(
"index"
),
shop
.
getUrlWebsite
().
lastIndexOf
(
"."
));
System
.
out
.
println
(
"------------------------------------"
);
//列表店铺存在将修改或增加今日爬取数据
if
(
shopUrl
.
contains
(
shopUrlLocahost
))
{
Example
example
=
this
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"commodityId"
,
commdoity
.
getId
()).
andEqualTo
(
"shopId"
,
shop
.
getId
());
List
<
ShopCommodity
>
listShop
=
this
.
selectByExample
(
example
);
ShopCommodity
shopCommodity
=
new
ShopCommodity
();
BigDecimal
price1
=
new
BigDecimal
(
price
);
shopCommodity
.
setCurrentprice
(
price1
);
if
(
listShop
.
size
()
>
0
)
{
// 修改售价
shopCommodity
.
setUpdateTime
(
new
Date
());
this
.
UpdateByExampleSelective
(
shopCommodity
,
example
);
continue
;
}
shopCommodity
.
setShopId
(
shop
.
getId
());
shopCommodity
.
setCommodityId
(
commdoity
.
getId
());
shopCommodity
.
setUpdateTime
(
new
Date
());
shopCommodity
.
setUploadTime
(
new
Date
());
this
.
insert
(
shopCommodity
);
}
}
}
}
// 消耗掉实体
EntityUtils
.
consume
(
response
.
getEntity
());
}
else
{
// 消耗掉实体
EntityUtils
.
consume
(
response
.
getEntity
());
}
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
finally
{
try
{
response
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
}
}
}
return
false
;
return
false
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论