python 获取淘宝商品信息
python cookie 获取淘宝商品信息
# //get_goods_from_taobao
import requests
import re
import xlsxwriter
cok='' # 此处写入登录之后自己的cookie
# 获取页面
def getHTMLText(url):
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36'}
usercookies=cok
cookies={}
for a in usercookies.split(';'):
name,value=a.strip().split('=',1)
cookies[name]=value
try:
r=requests.get(url,cookies=cookies,headers=headers,timeout=60)
r.raise_for_status()
r.encoding=r.apparent_encoding
return r.text
except:
return''
# 外汇MT4教程,查找数据
def parsePage(ilt,html):
try:
print('爬取成功')
plt=re.findall(r'\"view_price\"\:\"[\d\.]*\"',html)
tlt=re.findall(r'\"raw_title\"\:\".*?\"',html)
for i in range(len(plt)):
price=eval(plt[i].split(':')[1])
title=eval(tlt[i].split(':')[1])
ilt.append([price,title])
except:
print('')
# 打印数据列表
def printGoodList(ilt):
tplt='{:4}\t{:8}\t{:16}'
print(tplt.format('序号','价格','名称'))
count=0
for c in ilt:
count=count+1
print(tplt.format(count,c[0],c[1]))
# 写入excel
def writetoexcel(list):
print('开始创建excel表格')
book = xlsxwriter.Workbook(u'淘宝数据.xlsx')
sheet = book.add_worksheet()
sheet.write(0, 0, '序号')
sheet.write(0, 1, '名称')
sheet.write(0, 2, '价格')
row = 1
col = 0
for index, item in enumerate(list):
print('写入第%s行数据'%row)
sheet.write(row, col, index + 1) # 写入序号值
sheet.write(row, col + 1, item[1]) # 写入名称
sheet.write(row, col + 2, item[0]) # 写入价格
row += 1
print('写入完成')
book.close() # 关闭
def main():
goods=input('请输入想查询的内容:'.strip()) # 输入想搜索的商品名称
depth=3 # 爬取的页数
start_url='http://s.taobao.com/search?q='+goods # 搜索接口地址
infoList=[]
for i in range(depth):
try:
page=i+1
print('正在爬取第%s页数据'%page)
url=start_url+'&s='+str(44*i)
html=getHTMLText(url)
parsePage(infoList,html)
except:
continue
printGoodList(infoList)
writetoexcel(infoList)
main()
原文链接:https://blog.csdn.net/a736755244/article/details/103351817
python 获取淘宝商品信息的更多相关文章
- 淘宝开放平台php-sdk测试 获取淘宝商品信息(转)
今天想使用淘宝开放平台的API获取商品详情,可是以前一直没使用过,看起来有点高深莫测,后然看开发入门,一步一步,还真有点感觉了,然后看示例,还真行了,记下来以后参考.其中遇到问题,后然解决了.因为我已 ...
- 利用Selenium爬取淘宝商品信息
一. Selenium和PhantomJS介绍 Selenium是一个用于Web应用程序测试的工具,Selenium直接运行在浏览器中,就像真正的用户在操作一样.由于这个性质,Selenium也是一 ...
- python3编写网络爬虫16-使用selenium 爬取淘宝商品信息
一.使用selenium 模拟浏览器操作爬取淘宝商品信息 之前我们已经成功尝试分析Ajax来抓取相关数据,但是并不是所有页面都可以通过分析Ajax来完成抓取.比如,淘宝,它的整个页面数据确实也是通过A ...
- 爬取淘宝商品信息,放到html页面展示
爬取淘宝商品信息 import pymysql import requests import re def getHTMLText(url): kv = {'cookie':'thw=cn; hng= ...
- Selenium+Chrome/phantomJS模拟浏览器爬取淘宝商品信息
#使用selenium+Carome/phantomJS模拟浏览器爬取淘宝商品信息 # 思路: # 第一步:利用selenium驱动浏览器,搜索商品信息,得到商品列表 # 第二步:分析商品页数,驱动浏 ...
- <day003>登录+爬取淘宝商品信息+字典用json存储
任务1:利用cookie可以免去登录的烦恼(验证码) ''' 只需要有登录后的cookie,就可以绕过验证码 登录后的cookie可以通过Selenium用第三方(微博)进行登录,不需要进行淘宝的滑动 ...
- 安卓sdk webview获取淘宝个人信息100项,源码。
1.贴出主要代码.这个不是python,python只涉及了服务端对信息提取结果的接受.主体是java + android + js.由于淘宝各模块都是二级子域名,不能只在一个页面完成所有请求,aj ...
- 使用Pyquery+selenium抓取淘宝商品信息
配置文件,配置好数据库名称,表名称,要搜索的产品类目,要爬取的页数 MONGO_URL = 'localhost' MONGO_DB = 'taobao' MONGO_TABLE = 'phone' ...
- python爬虫-淘宝商品密码(图文教程附源码)
今天闲着没事,不想像书上介绍的那样,我相信所有的数据都是有规律可以寻找的,然后去分析了一下淘宝的商品数据的规律和加密方式,用了最简单的知识去解析了需要的数据. 这个也让我学到了,解决问题的方法不止一个 ...
随机推荐
- HTML5 回到顶部
图片: html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...
- css3 渐变色兼容移动端
.group_1 background #1a78f3 // 兼容不显示渐变色的浏览器 background: linear-gradient(180deg, #1a78f3 , #fff); bac ...
- APICloud框架——总结一下最近开发APP遇到的一些问题 (二)
高度自适应 flex布局 允许子元素伸缩 手机号正则 function checkPhone(data){ if(!(/^1[34578]\d{9}$/.test(data))){ alert(&qu ...
- JAVA 的StringBuffer类
StringBuffer类和String一样,也用来代表字符串,只是由于StringBuffer的内部实现方式和String不同,所以StringBuffer在进行字符串处理时,不生成新的对象,在内存 ...
- 腾讯云ubuntu16.04安装MySql5.7未提示密码设置且无法登陆解决
一.安装 sudo apt-get update sudo apt install mysql-server 二.修改密码 1.由于安装过程中未提示要设置密码,且使用sudo mysql_secure ...
- springboot bootstrap.yml 和 application.yml
bootstrap.yml可以理解成系统级别的一些参数配置,这些参数一般是不会变动的 application.yml 可以用来定义应用级别的,如果搭配spring-cloud-config使用 app ...
- sql find_in_set在oracle下的解决方案
比如一张表: artile (id,type,content); type:1表示文艺类,2表示小说类,3表示传记,4表示传说,等等5,6,7,8 表数据: id type content 1 3,1 ...
- flask-sqlalchemy报错 Object '<User at xxxx>' is already attached to session '1' (this is '2')
报错: Object '<User at xxxx>' is already attached to session '1' (this is '2') 结论: 两个不同的db ...
- https://www.cnblogs.com/limanjihe/p/10184327.html
https://www.cnblogs.com/limanjihe/p/10184327.html https://blog.csdn.net/xnnswmzdszyd/article/details ...
- 用 Flask 来写个轻博客 (4) — (M)VC_创建数据模型和表
目录 目录 前文列表 扩展阅读 定义数据模型 models 创建表 前文列表 用 Flask 来写个轻博客 (1) - 创建项目 用 Flask 来写个轻博客 (2) - Hello World! 用 ...