美文网首页
Python爬虫学习100练003

Python爬虫学习100练003

作者: 夜雨_87aa | 来源:发表于2018-03-28 23:34 被阅读0次

-- coding:utf-8 --

2018年3月28日

爬取淘宝商品信息存到EXcel

from urllib import request
import re
import requests
from openpyxl import Workbook
value=[['商品名称','价格','月销量']]
def gethttp():
res = requests.get(url)
html=res.text
req=r'{"cat":".?","title":"(.?)","pic_url".?jpg","price":"(.?)".?"month_sales":"(.?)"'
req=re.compile(req,re.S)
html=req.findall(html)
for title,price,sales in html:
value.append([title,price,sales])
def cunchu():
wb=Workbook()
sheet=wb.active
sheet.title="商品信息"
for i in range(0,len(value)):
for j in range(0,3):
sheet.cell(row=i+1,column=j+1).value=value[i][j]
wb.save("淘宝.xlsx")
if name == "main":
url1="https://s.taobao.com/search?q="
name="手机"
for i in range(1,100):
url2="&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306&p4ppushleft=5%2C48&s={j}".format(j=i*48)
url=str(url1+name+url2)
gethttp()
print("正在爬取第%s页"%i)
cunchu()
print("爬取完毕!")

相关文章

  • Python爬虫学习100练003

    -- coding:utf-8 -- 2018年3月28日 爬取淘宝商品信息存到EXcel from urllib...

  • Python爬虫学习100练001

    爬取菜鸟教程最新文章标题以及查看链接并写入excel文件中 -- coding:utf-8 -- 2018年3月2...

  • Python爬虫学习100练002

    爬取80s网站2018年电视剧作品主图片 -- coding:utf-8 -- 2018年3月25日 下载图片r...

  • Python爬虫学习(十六)初窥Scrapy

    Python爬虫学习(一)概述Python爬虫学习(二)urllib基础使用Python爬虫学习(三)urllib...

  • 资料

    Python爬虫系列(一)初期学习爬虫的拾遗与总结(11.4更) Python爬虫学习系列教程 Python爬虫学习手册

  • Python爬虫学习系列教程

    转自: 静觅»Python爬虫学习系列教程 Python爬虫学习系列教程 Python版本:2.7 一、爬虫入门 ...

  • 爬虫入门

    为什么要学习爬虫? Python做爬虫优势 关于Python网络爬虫,我们需要学习的有: 什么是爬虫? 网络爬虫(...

  • Python爬虫学习之小结(一)

    到目前为止,Python爬虫学习已经写了八篇文章,分别是: Python爬虫学习(一)概述Python爬虫学习(二...

  • python爬虫学习-day7-实战

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

  • Python 基础爬虫目录

    目录 python爬虫学习-day1 python爬虫学习-day2正则表达式 python爬虫学习-day3-B...

网友评论

      本文标题:Python爬虫学习100练003

      本文链接:https://www.haomeiwen.com/subject/gnjpcftx.html