python抓取京東商城手機列表url實例代碼
#-*- coding: UTF-8 -*-
'''
Created on 2013-12-5
@author: good-temper
'''
import urllib2
import bs4
import time
def getPage(urlStr):
'''
獲取頁面內(nèi)容
'''
content = urllib2.urlopen(urlStr).read()
return content
def getNextPageUrl(currPageNum):
#http://list.jd.com/9987-653-655-0-0-0-0-0-0-0-1-1-頁碼-1-1-72-4137-33.html
url = u'http://list.jd.com/9987-653-655-0-0-0-0-0-0-0-1-1-'+str(currPageNum+1)+'-1-1-72-4137-33.html'
#是否有下一頁
content = getPage(url);
soup = bs4.BeautifulSoup(content)
list = soup.findAll('span',{'class':'next-disabled'});
if(len(list) == 0):
return url
return ''
def analyzeList():
pageNum = 0
list = []
url = getNextPageUrl(pageNum)
while url !='':
soup = bs4.BeautifulSoup(getPage(url))
pagelist = soup.findAll('div',{'class':'p-name'})
for elem in pagelist:
soup1 = bs4.BeautifulSoup(str(elem))
list.append(soup1.find('a')['href'])
pageNum = pageNum+1
print pageNum
url = getNextPageUrl(pageNum)
return list
def analyzeContent(url):
return ''
def writeToFile(list, path):
f = open(path, 'a')
for elem in list:
f.write(elem+'\n')
f.close()
if __name__ == '__main__':
list = analyzeList()
print '共抓取'+str(len(list))+'條\n'
writeToFile(list, u'E:\\jd_phone_list.dat');
- python+selenium小米商城紅米K40手機自動搶購的示例代碼
- python框架Django實戰(zhàn)商城項目之工程搭建過程圖文詳解
- python簡單商城購物車實例代碼
- Python 實現(xiàn)購物商城,含有用戶入口和商家入口的示例
- python爬蟲框架scrapy實戰(zhàn)之爬取京東商城進階篇
- python爬蟲實戰(zhàn)之爬取京東商城實例教程
- python 實現(xiàn)網(wǎng)上商城,轉(zhuǎn)賬,存取款等功能的信用卡系統(tǒng)
- python實現(xiàn)簡單購物商城
- python實現(xiàn)淘寶購物系統(tǒng)
- Python實現(xiàn)購物系統(tǒng)(示例講解)
- Python實現(xiàn)信用卡系統(tǒng)(支持購物、轉(zhuǎn)賬、存取錢)
- 基于Python實現(xiàn)的購物商城管理系統(tǒng)
相關(guān)文章
Jupyter Notebook/VSCode導出PDF中文不顯示的解決
這篇文章主要介紹了Jupyter Notebook/VSCode導出PDF中文不顯示的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06Python使用pandasai實現(xiàn)數(shù)據(jù)分析
本文主要介紹了Python使用pandasai實現(xiàn)數(shù)據(jù)分析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-06-06

在python image 中安裝中文字體的實現(xiàn)方法