代码拉取完成,页面将自动刷新
import requests
# 价格动态
url='https://icps.suning.com/icps-web/getVarnishAllPriceNoCache/000000011715217902,000000011657719979,000000010591170237_759_7590199_0000000000,0000000000,0000000000_1_getClusterPrice.jsonp?callback=getClusterPrice'
# url='https://product.suning.com/0000000000/11715217902.html?utm_source=union&utm_medium=005007&adtype=5&utm_campaign=b760b4de-1865-4485-b475-f30f67f5b9f2&union_place=un'
response = requests.get(url)
# print(response.text)
import execjs
# jsenv = execjs.get().name
ctx = execjs.compile('function getClusterPrice(a){return a;};')
e = ctx.eval(response.text.replace(';','')) # 可以直接执行JS代码
# # e = execjs.eval(response.text.replace(';',''))
print(len(e))
#!/usr/bin/env python3
# BeautifulSoup4简介
import time
def selen(url):
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
chrome_opt = Options() # 创建参数设置对象.
# chrome_opt.add_argument('--headless') # 无界面化.
# chrome_opt.add_argument('--disable-gpu') # 配合上面的无界面化.
# chrome_opt.add_argument('--window-size=1366,768') # 设置窗口大小, 窗口大小会有影响.
prefs = {
'profile.default_content_setting_values' : {
'images' : 2
}
}
chrome_opt.add_experimental_option('prefs',prefs)
# 创建Chrome对象并传入设置信息.
driver = webdriver.Chrome(chrome_options=chrome_opt)
# driver = webdriver.Chrome() # 创建Chrome对象.
driver.implicitly_wait(10) # seconds
driver.get(url)
myDynamicElement = driver.find_element_by_xpath('//*[@class="mainprice"]')
text = driver.page_source
print(myDynamicElement.text)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。