代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
from lxml import etree
import requests
from config import proxy
# 代理 IP
_proxy = requests.get(proxy).text
proxies = {
'http': 'http://' + _proxy
}
def get_img_url(obj):
# url = 'https://itemcdn.tmall.com/1688offer/icoss2216880252cb747993ec73eb32'
Header = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'no-cache',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'none',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'
}
res = requests.get(obj.url,headers=Header,proxies=proxies)
html = etree.HTML(res.text)
urlStr = html.xpath("//img[@alt='\\\"undefined\\\"']/@src")
obj.imgUrls = []
for url in urlStr:
obj.imgUrls.append(url[2:-2])
print("解析一页数据成功!")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。