Как импортировать товары с чужого сайта Wordpress на свой wp?
С wp работаю первый раз
хотелось бы узнать у более опытных людей как это сделать «по человечески»
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('//www.example.com')
driver.delete_all_cookies()
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('//www.example.com')
driver.delete_cookie('cookie_name')
import json
from selenium import webdriver
driver = webdriver.Chrome()
cookies = driver.get_cookies()
with open('cookies.txt', 'w') as file:
json.dump(cookies, file)
from selenium import webdriver
import json
driver = webdriver.Chrome()
with open('cookies.txt', 'r') as file:
cookies = json.load(file)
for cookie in cookies:
driver.add_cookie(cookie)
driver.get("//www.example.com")
from selenium import webdriver
cookie = {
'name': 'cookie_name',
'value': 'cookie_value',
'path': '/',
'secure': False
}
driver = webdriver.Chrome()
driver.add_cookie(cookie)
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('//www.example.com')
cookie_name = 'cookie_name'
cookie = driver.get_cookie(cookie_name )
if cookie:
print(f"Cookie '{cookie_name}' found: {cookie}")
else:
print(f"Cookie '{cookie_name}' not found.")
function test() {
global $product;
if ($product->is_type('variable')) {
$current_variation_id = $product->get_variation_id();
$variations = $product->get_available_variations();
foreach ($variations as $variation) {
if ($current_variation_id === $variation['variation_id']) {
if (isset($variation['variation_description'])) {
echo $variation['variation_description'];
}
break;
}
}
}
}
add_action('woocommerce_after_shop_loop_item', 'test');
import os
# path to main directory
path = '/your/path'
# table
files = {
'file_1.txt': 'dir_1',
'file_2.txt': 'dir_1/dir_2',
'file_3.txt': 'dir_1/dir_2/dir_3'
# others
}
# moving files
for file, directory in files.items():
path_file = os.path.join(path, file)
path_dir = os.path.join(path, directory)
# checking for existence and creating directories if needed
if not os.path.exists(path_dir):
os.makedirs(path_dir)
# checking for existence of the file in the target directory
if os.path.exists(os.path.join(path_dir, file)):
print(f"File {file} already exists in directory {directory}, skip.")
else:
os.rename(path_file, os.path.join(path_dir, file))
print(f"The {file} file has been moved to a folder {directory}, success.")
# example moving:
#
# /your/path
# |-- /dir_1/file_1.txt
# |-- /dir_1/dir_2/file_2.txt
# |-- /dir_1/dir_2/dir_3/file_3.txt
Я могу как-то отследить эту ошибку (не в определенной части кода, а вообще где угодно), в положительном случае
from jspybridge import JSPyBridge
bridge = JSPyBridge()
try:
# код, который отработает без ошибок
except jspybridge.JSPyBridgeError as e:
# код, который выбросит исключение, например, при краше Nodejs
print(f"ОшибкО: {e}")
import {JSPyBridge, JSPyBridgeError} from 'jspybridge';
const bridge = new JSPyBridge();
try {
// код, который отработает без ошибок
} catch (error) {
if (error instanceof JSPyBridgeError) {
// код, который выбросит исключение, например, при краше Nodejs
console.error(`ОшибкО: ${error.message}`);
}
}
я могу ее просто игнорировать или нужно как-то перезапустить код?
Либо возможно как-то избавиться от этой ошибки?
Но сейчас я использую wordpress и wp_enqueue_script. Можно ли как-то добавить "module" к wp_enqueue_script?
function my_scripts() {
wp_enqueue_script('unique_script_id', get_template_directory_uri() . '/path/script.js', [], null, true);
wp_script_add_data('unique_script_id', 'type', 'module');
}
add_action('wp_enqueue_scripts', 'my_scripts');
Как быть, если мой сайт предназначен не на ру аудиторию?
Можно ли как-то иначе это сделать или только такой вариант?
И еще вариант, может быть так, если я делаю сайт с доменом .com и он предназначен исключительно не на Ру аудиторию т.к там даже перевода на русский не будет, то я могу использовать зарубежный хостинг и ничего не делать для локализации данных в рф? Тип, если у меня целевая аудитория другая
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import time
url = 'https://discord.com/channels/1097401827202445382/1097674067601010709'
# driver
driver = webdriver.Chrome()
driver.get(url)
print('your manual authorization, the script is waiting for 30 seconds')
time.sleep(30)
try:
print('find and click element button friends')
button_element = driver.find_element(By.XPATH, '//*[@id="app-mount"]/div[2]/div[1]/div[1]/div/div[2]/div/div/div/div/div[3]/section/div/div[2]/div[4]')
button_element.click()
except NoSuchElementException:
print('error: element button friends not found')
time.sleep(5)
driver.quit()
exit()
time.sleep(5)
try:
print('find scroll element')
element = driver.find_element(By.XPATH, '//*[@id="app-mount"]/div[2]/div[1]/div[1]/div/div[2]/div/div/div/div/div[3]/div[2]/div[2]/aside/div')
except NoSuchElementException:
print('error: scroll element not found')
time.sleep(5)
driver.quit()
exit()
print('move cursor to element')
action = ActionChains(driver)
action.move_to_element(element).perform()
print('scroll down')
driver.execute_script('arguments[0].scrollTop += 300', element)
print('mission complete, thanks to Uncle Misha')
time.sleep(5)
print('exit')
driver.quit()
# your manual authorization, the script is waiting for 30 seconds
# find and click element button friends
# find scroll element
# move cursor to element
# scroll down
# mission complete, thanks to Uncle Misha
exit
import requests
url = "http://detailing69.ru/wb_cookies.json"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
}
res = requests.get(url, headers=headers)
if res.status_code == 200:
print(res.json())
else:
print(f"ОшибкО: {res.status_code}")
# [{'seller': 'Оксана ', 'cookies': {'general': '1', 'statistics': '2', 'supplies': '3', 'advertisement': '4'}}]