利用python爬虫怎么对京东进行爬取

  介绍

利用python爬虫怎么对京东进行爬取?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

代码

# !/usr/bin/env  python   #,- *安康;编码:utf-8  - * -   #,@File : HtmlParser.py   #,@Author:赵路仓   #,@Date : 2020/3/17   #,@Desc :   #,@Contact : 398333404 @qq.com   import  json      得到lxml  import  etree   import 请求   得到bs4  import  BeautifulSoup         url=癶ttps://search.jd.com/Search?keyword=ps4& enc=utf-8& wq=ps4& pvid=cf0158c8664442799c1146a461478c9c"   头={   ,& # 39;权威# 39;:,& # 39;search.jd.com& # 39;   ,& # 39;方法# 39;:,& # 39;得到# 39;   ,& # 39;path & # 39;:, & # 39;/s_new.php ?关键字=% E6 % 89% 8 b % E6 % 9 c % BA& enc=utf-8& qrst=1, rt=1,停止=1,vt=2, wq=% E6 % 89% 8 b % E6 % 9 c % BA& cid2=653, cid3=655,页面=4,s=84,滚动=y& log_id=1529828108.22071, tpl=3 _m& show_items=7651927, 7367120, 7056868, 7419252, 6001239, 5934182, 4554969, 3893501, 7421462, 6577495, 26480543553, 7345757, 4483120, 6176077, 6932795, 7336429, 5963066, 5283387, 25722468892, 7425622, 4768461 & # 39;   ,& # 39;计划# 39;:,& # 39;https # 39;   ,& # 39;推荐人# 39;:,& # 39;https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&,以便=utf-8& qrst=1, rt=1,停止=1,vt=2, wq=% E6 % 89% 8 b % E6 % 9 c % BA& cid2=653, cid3=655,页面=3,s=58,单击=0 & # 39;   ,& # 39;用户代理# 39;:,& # 39;Mozilla/5.0, (Windows  NT  6.1;, Win64;, x64), AppleWebKit/537.36, (KHTML, like 壁虎),Chrome/66.0.3359.139  Safari/537.36 & # 39;   ,& # 39;x-requested-with& # 39;:, & # 39; xmlhttprequest # 39;   }      def 页面(页面):   ,打印(“开始“)=,url “https://search.jd.com/Search?keyword=ps4&,以便=utf-8& qrst=1, rt=1,停止=1,vt=1, wq=ps4&页面=?页+“,s=181,单击=0”;   ,r=requests.get (url、超时=3头=头)   r.encoding=r.apparent_encoding   ,#打印(r.text)   ,b=BeautifulSoup (r.text,“html.parser")   ,#打印(b.prettify ())=,,_element  etree.HTML (r.text)=,,datas  _element.xpath(& # 39;//李(包含(@class,“gl-item")] & # 39;)   ,打印(数据)   ,for  data 拷贝数据:   p_price 才能=,data.xpath (& # 39; div/div [@class=皃-price"]/强/我/text () & # 39;)   p_comment 才能=,data.xpath (& # 39; div/div[5]/强//text () & # 39;)   p_name 才能=,data.xpath (& # 39; div/div [@class=皃-name  p-name-type-2"]//em/text () & # 39;)   p_href 才能=,data.xpath (& # 39; div/div [@class=皃-name  p-name-type-2"]//@href& # 39;)   评论=& # 39;才能,. join (p_comment) & # 39;   时间=name 才能;& # 39;. join (p_name), & # 39;   时间=price 才能;& # 39;. join (p_price), & # 39;   时间=href 才能;& # 39;. join (p_href), & # 39;   打印才能(名称、价格、p_comment href)      if  __name__==癬_main__":   ,页面(“5“)

爬取结果

利用python爬虫怎么对京东进行爬取

看完上述内容,你们掌握利用python爬虫怎么对京东进行爬取的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!

利用python爬虫怎么对京东进行爬取