python 爬蟲爬取京東ps4售賣情況
更新時間:2020年12月18日 10:51:45 作者:霧霾王者
這篇文章主要介紹了python 如何用爬蟲爬取京東ps4售賣情況,幫助大家更好的利用python爬取自己想要的數(shù)據(jù),感興趣的朋友可以了解下
代碼
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : HtmlParser.py # @Author: 趙路倉 # @Date : 2020/3/17 # @Desc : # @Contact : 398333404@qq.com import json from lxml import etree import requests from bs4 import BeautifulSoup url="https://search.jd.com/Search?keyword=ps4&enc=utf-8&wq=ps4&pvid=cf0158c8664442799c1146a461478c9c" head={ 'authority': 'search.jd.com', 'method': 'GET', 'path': '/s_new.php?keyword=%E6%89%8B%E6%9C%BA&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&wq=%E6%89%8B%E6%9C%BA&cid2=653&cid3=655&page=4&s=84&scrolling=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', 'scheme': 'https', 'referer': 'https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&wq=%E6%89%8B%E6%9C%BA&cid2=653&cid3=655&page=3&s=58&click=0', 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36', 'x-requested-with': 'XMLHttpRequest', } def page(page): print("開始") url = "https://search.jd.com/Search?keyword=ps4&enc=utf-8&qrst=1&rt=1&stop=1&vt=1&wq=ps4&page="+page+"&s=181&click=0" r=requests.get(url,timeout=3,headers=head) r.encoding=r.apparent_encoding # print(r.text) b=BeautifulSoup(r.text,"html.parser") #print(b.prettify()) _element = etree.HTML(r.text) datas = _element.xpath('//li[contains(@class,"gl-item")]') print(datas) for data in datas: p_price = data.xpath('div/div[@class="p-price"]/strong/i/text()') p_comment = data.xpath('div/div[5]/strong/a/text()') p_name = data.xpath('div/div[@class="p-name p-name-type-2"]/a/em/text()') p_href = data.xpath('div/div[@class="p-name p-name-type-2"]/a/@href') comment=' '.join(p_comment) name = ' '.join(p_name) price = ' '.join(p_price) href = ' '.join(p_href) print(name,price,p_comment,href) if __name__=="__main__": page("5")
爬取結(jié)果
以上就是python 爬蟲爬取某東ps4售賣情況的詳細內(nèi)容,更多關(guān)于python 爬蟲的資料請關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:
- python使用Word2Vec進行情感分析解析
- Python實現(xiàn)購物評論文本情感分析操作【基于中文文本挖掘庫snownlp】
- python snownlp情感分析簡易demo(分享)
- Python 京東云無線寶消息推送功能
- python基于scrapy爬取京東筆記本電腦數(shù)據(jù)并進行簡單處理和分析
- python pyppeteer 破解京東滑塊功能的代碼
- Python實現(xiàn)京東搶秒殺功能
- Python之京東商品秒殺的實現(xiàn)示例
- Python基于BeautifulSoup爬取京東商品信息
- 使用 Python 在京東上搶口罩的思路詳解
- springboot使用@value讀取配置的方法
- 基于Python+Appium實現(xiàn)京東雙十一自動領(lǐng)金幣功能
- python 爬取京東指定商品評論并進行情感分析
相關(guān)文章
python實現(xiàn)一個點繞另一個點旋轉(zhuǎn)后的坐標
今天小編就為大家分享一篇python實現(xiàn)一個點繞另一個點旋轉(zhuǎn)后的坐標,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12Python pandas實現(xiàn)excel工作表合并功能詳解
這篇文章主要介紹了Python pandas實現(xiàn)excel工作表合并功能以及相關(guān)實例代碼,需要的朋友們參考學習下。2019-08-08python筆記(1) 關(guān)于我們應(yīng)不應(yīng)該繼續(xù)學習python
關(guān)于Python,如果你要學習,建議大家查看一下網(wǎng)站:因為本人也是剛剛決定收集點零碎時間來學習下它,推薦可能并不是最好的2012-10-10DataFrame 數(shù)據(jù)合并實現(xiàn)(merge,join,concat)
這篇文章主要介紹了DataFrame 數(shù)據(jù)合并實現(xiàn)(merge,join,concat),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-06-06Python中使用__new__實現(xiàn)單例模式并解析
單例模式是一個經(jīng)典設(shè)計模式,簡要的說,一個類的單例模式就是它只能被實例化一次,實例變量在第一次實例化時就已經(jīng)固定。 這篇文章主要介紹了Python中使用__new__實現(xiàn)單例模式并解析 ,需要的朋友可以參考下2019-06-06