python reptile: Taobao picture reptile

1. Taobao site law

https:. //s.taobao.com /list?spm=a21bo.2017 201867-links-0.6.5af911d9OXqjyt & q = search word & cat = 16 & style = grid & seller_type = taobao & bcoffset = 0 & s = (p -1) * 60

1.1 Note:

Data in the source code can be directly crawl; no source code, web pages but some information is hidden in the js file, then need to get caught.

1.2 Copy image URL on ebay page:

https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i3/224680019/O1CN01uIilBc1C0k57Kg2Kv_!!0-saturn_solar.jpg_250x250.jpg_.webp at this time we see only a small figure, not HD Fig. Resolving the Web site:

Images saved in the location of the server, do not control:

https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i3/224680019/:

Photo size and other important information:

jpg_250x250.jpg_.webp

The core part of the photo data: O1CN01uIilBc1C0k57Kg2Kv _ !! 0-saturn_solar

Search photos 1.3 core data in the source code:

O1CN01uIilBc1C0k57Kg2Kv _ !! 0-saturn_solar, you will find url, as shown in photo. Refresher "pic_url": "// g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i3/224680019/O1CN01uIilBc1C0k57Kg2Kv_!!0-saturn_solar.jpg". Prefixed with https, open to see high-definition big picture browser.
[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-kiMroQDV-1584149980058) (attachment: image.png)]

1.3 by regular extraction Photo URL: "pic_url": "? //(.*)"

import urllib.request
import re

keyname='短裙'
key=urllib.request.quote(keyname)

for i in range(0,5):
    url='https://s.taobao.com/list?q="+key+"&cat=16&style=grid&seller_type=taobao&bcoffset=0&s='+str(i*60)
    data=urllib.request.urlopen(url).read().decode('utf-8','ignore')
    #正则提取
    pat='pic_url":"//(.*?)"'
    imageurl=re.compile(pat).findall(data)
    print(imageurl)
import urllib.request
import re

keyname='短裙'
key=urllib.request.quote(keyname)

headers=('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0')
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)

for i in range(0,5):
    url='https://s.taobao.com/list?q="+key+"&cat=16&style=grid&seller_type=taobao&bcoffset=0&s='+str(i*60)
    data=urllib.request.urlopen(url).read().decode('utf-8','ignore')
    #正则提取
    pat='"pic_url":"//(.*?)"'
    imageurl=re.compile(pat).findall(data)
    print(imageurl)
import urllib.request
import re

keyname="神舟"
key=urllib.request.quote(keyname) #编码

#尝试爬取前三页内容
for i in range(0,3): 
    #构造页面URL
    url="https://s.taobao.com/search?q="+key+"&s=44"
    data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
    pat='pic_url":"//(.*?)"'
    #获得图片URL
    imagelist=re.compile(pat).findall(data)
    print(imagelist)


import urllib.request
import re

keyname="神舟"
key=urllib.request.quote(keyname) #编码

#尝试爬取前三页内容
for i in range(0,3): 
    #构造页面URL
    url="https://s.taobao.com/search?q="+key+"&s=44"
    data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
    pat='pic_url":"//(.*?)"'
    #获得图片URL
    imagelist=re.compile(pat).findall(data)
    for j in range(0,len(imagelist)):
        thisimg=imagelist[j]
        #构造图片URL
        thisimgurl="http://"+thisimg
        file=" F:/jupyterpycodes/python_pachongfenxi/result/taobaoIMG/"+str(i)+str(j)+".jpg"


Published 47 original articles · won praise 35 · views 1816

Guess you like

Origin blog.csdn.net/weixin_43412569/article/details/104855018