爬取动态加载过来的详细页【当当图书为例】

当当首页搜索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)

猜你喜欢

转载自blog.csdn.net/weixin_45044349/article/details/121031489