当当首页搜索python的网址http://search.dangdang.com/?key=python&act=input&page_index=1
点击框里a便签将会跳转详细页,我想要爬取如下内容:
http://product.dangdang.com/28486010.html
与之对应的动态路由为最后得出的。
但是他右键查看源代码时,找不到;如此便是:数据是动态加载过来的;这时使用Fidder软件进行查找url。如图:
然后去去每个url的响应内容里面查看需要的数据在哪个url
这时找到了所需路由。
爬虫则需要拼接url:
拼成详情页的链接
product_id = response.url.replace("http://product.dangdang.com/","").replace(".html","")
detail_url = "http://product.dangdang.com/index.php?r=callback%2Fdetail&productId={}&templateType=publish&describeMap=01000031453%3A1&shopId=0&categoryPath=01.31.02.00.00.00".format(product_id)
print(detail_url)