@dyyz1993/agent-browser 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/bin/agent-browser-darwin-arm64 +0 -0
- package/dist/__tests__/utils/free-port.d.ts +2 -0
- package/dist/__tests__/utils/free-port.d.ts.map +1 -0
- package/dist/__tests__/utils/free-port.js +18 -0
- package/dist/__tests__/utils/free-port.js.map +1 -0
- package/dist/__tests__/utils/parseCli.d.ts.map +1 -1
- package/dist/__tests__/utils/parseCli.js +0 -8
- package/dist/__tests__/utils/parseCli.js.map +1 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +32 -12
- package/dist/actions.js.map +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +12 -17
- package/dist/browser.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +11 -13
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/connection.d.ts.map +1 -1
- package/dist/cli/connection.js +86 -47
- package/dist/cli/connection.js.map +1 -1
- package/dist/cli/flags.d.ts +1 -0
- package/dist/cli/flags.d.ts.map +1 -1
- package/dist/cli/flags.js +8 -1
- package/dist/cli/flags.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +75 -23
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/output.d.ts.map +1 -1
- package/dist/cli/output.js +0 -32
- package/dist/cli/output.js.map +1 -1
- package/dist/cli.js +150 -15
- package/dist/cli.js.map +1 -1
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +285 -280
- package/dist/daemon.js.map +1 -1
- package/dist/flow/exporters/cypress.d.ts +9 -0
- package/dist/flow/exporters/cypress.d.ts.map +1 -0
- package/dist/flow/exporters/cypress.js +256 -0
- package/dist/flow/exporters/cypress.js.map +1 -0
- package/dist/flow/exporters/index.d.ts +2 -0
- package/dist/flow/exporters/index.d.ts.map +1 -1
- package/dist/flow/exporters/index.js +2 -0
- package/dist/flow/exporters/index.js.map +1 -1
- package/dist/flow/exporters/selenium.d.ts +9 -0
- package/dist/flow/exporters/selenium.d.ts.map +1 -0
- package/dist/flow/exporters/selenium.js +298 -0
- package/dist/flow/exporters/selenium.js.map +1 -0
- package/dist/flow/flow-executor.d.ts +2 -0
- package/dist/flow/flow-executor.d.ts.map +1 -1
- package/dist/flow/flow-executor.js +143 -49
- package/dist/flow/flow-executor.js.map +1 -1
- package/dist/flow/index.d.ts +1 -1
- package/dist/flow/index.d.ts.map +1 -1
- package/dist/flow/index.js +1 -1
- package/dist/flow/index.js.map +1 -1
- package/dist/flow/output.js.map +1 -1
- package/dist/flow/plugin-system.d.ts.map +1 -1
- package/dist/flow/plugin-system.js.map +1 -1
- package/dist/flow/presets/console-capture.js +31 -0
- package/dist/flow/presets/fetch-capture.js +78 -0
- package/dist/flow/presets/sse-stream.js +67 -0
- package/dist/flow/presets/xhr-only.js +34 -0
- package/dist/flow/recorder-to-flow.js.map +1 -1
- package/dist/flow/site-manager.js.map +1 -1
- package/dist/flow/types.d.ts +15 -0
- package/dist/flow/types.d.ts.map +1 -1
- package/dist/flow/yaml-parser.d.ts.map +1 -1
- package/dist/flow/yaml-parser.js +2 -0
- package/dist/flow/yaml-parser.js.map +1 -1
- package/dist/human-mouse.d.ts.map +1 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +1 -12
- package/dist/protocol.js.map +1 -1
- package/dist/rc-config.d.ts.map +1 -1
- package/dist/rc-config.js +1 -2
- package/dist/rc-config.js.map +1 -1
- package/dist/snapshot-store.d.ts +6 -0
- package/dist/snapshot-store.d.ts.map +1 -1
- package/dist/snapshot-store.js +15 -0
- package/dist/snapshot-store.js.map +1 -1
- package/dist/snapshot.d.ts.map +1 -1
- package/dist/snapshot.js +48 -30
- package/dist/snapshot.js.map +1 -1
- package/dist/stream-server-standalone.d.ts.map +1 -1
- package/dist/stream-server-standalone.js.map +1 -1
- package/dist/stream-server.d.ts.map +1 -1
- package/dist/stream-server.js +38 -13
- package/dist/stream-server.js.map +1 -1
- package/dist/test-live.js +5 -5
- package/dist/test-live.js.map +1 -1
- package/dist/types.d.ts +2 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/viewer-script.d.ts.map +1 -1
- package/dist/viewer-script.js +8 -2
- package/dist/viewer-script.js.map +1 -1
- package/package.json +12 -3
- package/scripts/check_goods_container.js +35 -0
- package/scripts/check_page_content.js +36 -0
- package/scripts/click_applause_rate.js +30 -0
- package/scripts/explore_jd_page.js +31 -0
- package/scripts/extract_all_jd_data.js +80 -0
- package/scripts/extract_jd_product_detail.js +62 -0
- package/scripts/extract_jd_products_correct_links.js +78 -0
- package/scripts/extract_jd_products_final.js +80 -0
- package/scripts/extract_jd_reviews.js +48 -0
- package/scripts/extract_jd_seafood_final.js +78 -0
- package/scripts/extract_multiple_products.js +77 -0
- package/scripts/extract_products_no_scroll.js +68 -0
- package/scripts/extract_products_simple.js +68 -0
- package/scripts/find_applause_rate.js +26 -0
- package/scripts/find_jd_links.js +28 -0
- package/scripts/find_main_content.js +20 -0
- package/scripts/find_product_cards.js +38 -0
- package/scripts/find_root_content.js +26 -0
- package/scripts/find_unique_products.js +55 -0
- package/scripts/get_jd_product_detail.js +16 -0
- package/scripts/get_jd_products.js +23 -0
- package/scripts/get_jd_seafood_products.js +44 -0
- package/scripts/get_product_details_from_images.js +54 -0
- package/scripts/verify-form.sh +67 -0
- package/scripts/verify-login.sh +65 -0
- package/scripts/verify-recording.sh +80 -0
- package/scripts/verify-upload.sh +41 -0
- package/skills/agent-browser/SKILL.md +49 -0
- package/bin/agent-browser-linux-x64 +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const result = {
|
|
3
|
+
keyword: "生鲜海鲜",
|
|
4
|
+
crawlTime: new Date().toISOString(),
|
|
5
|
+
products: []
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const containers = document.querySelectorAll('._goodsContainer_1p2ae_1');
|
|
9
|
+
const seenLinks = new Set();
|
|
10
|
+
|
|
11
|
+
containers.forEach((container, index) => {
|
|
12
|
+
const link = container.querySelector('a[href]');
|
|
13
|
+
if (!link) return;
|
|
14
|
+
|
|
15
|
+
const href = link.href;
|
|
16
|
+
if (seenLinks.has(href)) return;
|
|
17
|
+
seenLinks.add(href);
|
|
18
|
+
|
|
19
|
+
const text = container.textContent || '';
|
|
20
|
+
const product = {
|
|
21
|
+
id: index + 1,
|
|
22
|
+
link: href
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const img = container.querySelector('img');
|
|
26
|
+
if (img) {
|
|
27
|
+
const src = img.getAttribute('data-src') || img.src;
|
|
28
|
+
if (src) product.image = src.substring(0, 150);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const priceMatch = text.match(/[¥¥]\s*(\d+\.?\d*)/);
|
|
32
|
+
if (priceMatch) {
|
|
33
|
+
product.price = priceMatch[1];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const salesMatch = text.match(/已售([\d\+万]+)/);
|
|
37
|
+
if (salesMatch) {
|
|
38
|
+
product.sales = salesMatch[1];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const shopMatch = text.match(/([^\s]{2,10}(?:旗舰店|专营店|京东自营))/);
|
|
42
|
+
if (shopMatch) {
|
|
43
|
+
product.shop = shopMatch[1];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const adIndex = text.indexOf('广告');
|
|
47
|
+
const titleStart = adIndex >= 0 ? adIndex + 2 : 0;
|
|
48
|
+
let title = text.substring(titleStart).trim();
|
|
49
|
+
|
|
50
|
+
title = title.replace(/已售[\d\+万]+/, '');
|
|
51
|
+
title = title.replace(/[\d\+万]+人加购/, '');
|
|
52
|
+
title = title.replace(/[\d\+万]+人种草/, '');
|
|
53
|
+
title = title.replace(/[\d\+万]+人浏览/, '');
|
|
54
|
+
title = title.replace(/[^\s]{2,10}(?:旗舰店|专营店|京东自营)/, '');
|
|
55
|
+
title = title.replace(/搜同款|关注|对比/g, '');
|
|
56
|
+
title = title.trim();
|
|
57
|
+
|
|
58
|
+
if (title.length > 5) {
|
|
59
|
+
product.title = title.substring(0, 100);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (product.title || product.price) {
|
|
63
|
+
result.products.push(product);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
})()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const applauseRateEl = document.querySelector('.applause-rate');
|
|
3
|
+
|
|
4
|
+
if (applauseRateEl) {
|
|
5
|
+
return {
|
|
6
|
+
elementFound: true,
|
|
7
|
+
elementText: applauseRateEl.textContent,
|
|
8
|
+
elementHTML: applauseRateEl.outerHTML.substring(0, 500)
|
|
9
|
+
};
|
|
10
|
+
} else {
|
|
11
|
+
const allElements = document.querySelectorAll('[class*="applause"], [class*="rate"]');
|
|
12
|
+
const elements = [];
|
|
13
|
+
allElements.forEach(el => {
|
|
14
|
+
elements.push({
|
|
15
|
+
className: el.className,
|
|
16
|
+
text: el.textContent?.substring(0, 100)
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
elementFound: false,
|
|
22
|
+
message: 'applause-rate element not found',
|
|
23
|
+
similarElements: elements.slice(0, 10)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
})()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const result = {
|
|
3
|
+
allLinks: [],
|
|
4
|
+
jdLinks: [],
|
|
5
|
+
productLinks: []
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const links = document.querySelectorAll('a[href*="jd"]');
|
|
9
|
+
|
|
10
|
+
links.forEach((link, index) => {
|
|
11
|
+
if (index < 20) {
|
|
12
|
+
result.allLinks.push({
|
|
13
|
+
href: link.href.substring(0, 100),
|
|
14
|
+
text: link.textContent?.substring(0, 50)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (link.href.includes('item.jd') || link.href.includes('product')) {
|
|
19
|
+
result.jdLinks.push({
|
|
20
|
+
href: link.href.substring(0, 100),
|
|
21
|
+
text: link.textContent?.substring(0, 50),
|
|
22
|
+
parentClass: link.parentElement?.className
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return result;
|
|
28
|
+
})()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const result = {
|
|
3
|
+
bodyChildren: []
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const bodyChildren = document.body.children;
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < Math.min(bodyChildren.length, 30); i++) {
|
|
9
|
+
const child = bodyChildren[i];
|
|
10
|
+
result.bodyChildren.push({
|
|
11
|
+
index: i,
|
|
12
|
+
tagName: child.tagName,
|
|
13
|
+
id: child.id,
|
|
14
|
+
className: child.className,
|
|
15
|
+
childrenCount: child.children.length
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return result;
|
|
20
|
+
})()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const result = {
|
|
3
|
+
bodyClasses: document.body.className,
|
|
4
|
+
children: []
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const mainContent = document.querySelector('main, #J_goodsList, [id*="goods"], [id*="product"]');
|
|
8
|
+
|
|
9
|
+
if (mainContent) {
|
|
10
|
+
result.mainContainer = {
|
|
11
|
+
id: mainContent.id,
|
|
12
|
+
className: mainContent.className,
|
|
13
|
+
childrenCount: mainContent.children.length
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
Array.from(mainContent.children).slice(0, 5).forEach((child, index) => {
|
|
17
|
+
result.children.push({
|
|
18
|
+
index,
|
|
19
|
+
tagName: child.tagName,
|
|
20
|
+
className: child.className,
|
|
21
|
+
id: child.id,
|
|
22
|
+
innerHTML: child.innerHTML.substring(0, 200)
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
Array.from(document.body.querySelectorAll('div')).slice(0, 20).forEach((div, index) => {
|
|
27
|
+
result.children.push({
|
|
28
|
+
index,
|
|
29
|
+
tagName: div.tagName,
|
|
30
|
+
className: div.className,
|
|
31
|
+
id: div.id,
|
|
32
|
+
innerHTML: div.innerHTML.substring(0, 200)
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
})()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const root = document.getElementById('root');
|
|
3
|
+
|
|
4
|
+
if (!root) {
|
|
5
|
+
return { error: 'root not found' };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const result = {
|
|
9
|
+
rootId: root.id,
|
|
10
|
+
childrenCount: root.children.length,
|
|
11
|
+
children: []
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < Math.min(root.children.length, 20); i++) {
|
|
15
|
+
const child = root.children[i];
|
|
16
|
+
result.children.push({
|
|
17
|
+
index: i,
|
|
18
|
+
tagName: child.tagName,
|
|
19
|
+
id: child.id,
|
|
20
|
+
className: child.className,
|
|
21
|
+
innerHTML: child.innerHTML.substring(0, 300)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return result;
|
|
26
|
+
})()
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
(async () => {
|
|
2
|
+
const result = {
|
|
3
|
+
products: []
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const containers = document.querySelectorAll('._goodsContainer_1p2ae_1');
|
|
7
|
+
|
|
8
|
+
containers.forEach((container, index) => {
|
|
9
|
+
if (index >= 10) return;
|
|
10
|
+
|
|
11
|
+
const product = {
|
|
12
|
+
index,
|
|
13
|
+
className: container.className,
|
|
14
|
+
text: container.textContent?.trim().substring(0, 300)
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const link = container.querySelector('a[href*="jd"]');
|
|
18
|
+
if (link) {
|
|
19
|
+
product.link = link.href;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const img = container.querySelector('img');
|
|
23
|
+
if (img) {
|
|
24
|
+
product.img = img.getAttribute('data-src')?.substring(0, 100) || img.src?.substring(0, 100);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const text = container.textContent || '';
|
|
28
|
+
|
|
29
|
+
const priceMatch = text.match(/[¥¥]\s*\d+\.?\d*/);
|
|
30
|
+
if (priceMatch) {
|
|
31
|
+
product.price = priceMatch[0];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const salesMatch = text.match(/已售[\d\+万]+/);
|
|
35
|
+
if (salesMatch) {
|
|
36
|
+
product.sales = salesMatch[0];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const shopMatch = text.match(/([^\s]+旗舰店|[^\s]+专营店)/);
|
|
40
|
+
if (shopMatch) {
|
|
41
|
+
product.shop = shopMatch[0];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const titleMatch = text.match(/([^\s]{5,50})/);
|
|
45
|
+
if (titleMatch && !titleMatch[0].includes('广告') && !titleMatch[0].includes('旗舰店')) {
|
|
46
|
+
product.title = titleMatch[0];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (product.price || product.shop || product.sales) {
|
|
50
|
+
result.products.push(product);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return result;
|
|
55
|
+
})()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const reviews = {};
|
|
3
|
+
|
|
4
|
+
const goodEl = document.querySelector('.filter-items a[data-tab="good"]');
|
|
5
|
+
const neutralEl = document.querySelector('.filter-items a[data-tab="neutral"]');
|
|
6
|
+
const badEl = document.querySelector('.filter-items a[data-tab="bad"]');
|
|
7
|
+
|
|
8
|
+
reviews.good = goodEl?.textContent?.trim() || '';
|
|
9
|
+
reviews.neutral = neutralEl?.textContent?.trim() || '';
|
|
10
|
+
reviews.bad = badEl?.textContent?.trim() || '';
|
|
11
|
+
|
|
12
|
+
const regionEl = document.querySelector('.address-item');
|
|
13
|
+
const region = regionEl?.textContent?.trim() || '';
|
|
14
|
+
|
|
15
|
+
return { reviews, region };
|
|
16
|
+
})()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const items = document.querySelectorAll('.gl-item');
|
|
3
|
+
const products = [];
|
|
4
|
+
|
|
5
|
+
items.forEach((item, index) => {
|
|
6
|
+
const titleEl = item.querySelector('.p-name a');
|
|
7
|
+
const priceEl = item.querySelector('.p-price');
|
|
8
|
+
const shopEl = item.querySelector('.p-shop a');
|
|
9
|
+
const salesEl = item.querySelector('.p-commit');
|
|
10
|
+
const linkEl = item.querySelector('.p-name a');
|
|
11
|
+
|
|
12
|
+
products.push({
|
|
13
|
+
index: index,
|
|
14
|
+
title: titleEl?.textContent?.trim() || '',
|
|
15
|
+
price: priceEl?.textContent?.trim() || '',
|
|
16
|
+
shop: shopEl?.textContent?.trim() || '',
|
|
17
|
+
sales: salesEl?.textContent?.trim() || '',
|
|
18
|
+
link: linkEl?.href || ''
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return products.slice(0, 10);
|
|
23
|
+
})()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
(async () => {
|
|
2
|
+
const result = {
|
|
3
|
+
products: []
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
window.scrollTo(0, 1000);
|
|
7
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
8
|
+
|
|
9
|
+
window.scrollTo(0, 3000);
|
|
10
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
11
|
+
|
|
12
|
+
const productCards = document.querySelectorAll('[data-point-id], .youLikeItem, [class*="item"]');
|
|
13
|
+
|
|
14
|
+
productCards.forEach((card, index) => {
|
|
15
|
+
if (index >= 15) return;
|
|
16
|
+
|
|
17
|
+
const product = {
|
|
18
|
+
index,
|
|
19
|
+
className: card.className,
|
|
20
|
+
title: '',
|
|
21
|
+
price: '',
|
|
22
|
+
shop: '',
|
|
23
|
+
link: ''
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const titleEl = card.querySelector('[class*="title"], [class*="name"], h3, h4, h5');
|
|
27
|
+
const priceEl = card.querySelector('[class*="price"], .price');
|
|
28
|
+
const shopEl = card.querySelector('[class*="shop"], [class*="store"], [class*="brand"]');
|
|
29
|
+
const linkEl = card.querySelector('a[href*="jd"]');
|
|
30
|
+
const imgEl = card.querySelector('img');
|
|
31
|
+
|
|
32
|
+
if (titleEl) product.title = titleEl.textContent?.trim() || '';
|
|
33
|
+
if (priceEl) product.price = priceEl.textContent?.trim() || '';
|
|
34
|
+
if (shopEl) product.shop = shopEl.textContent?.trim() || '';
|
|
35
|
+
if (linkEl) product.link = linkEl.href || '';
|
|
36
|
+
if (imgEl && imgEl.src) product.image = imgEl.src.substring(0, 100);
|
|
37
|
+
|
|
38
|
+
if (product.title || product.price || product.link) {
|
|
39
|
+
result.products.push(product);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return result;
|
|
44
|
+
})()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
(async () => {
|
|
2
|
+
const result = {
|
|
3
|
+
products: []
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const wrappers = document.querySelectorAll('._wrapper_8g5fc_1');
|
|
7
|
+
|
|
8
|
+
wrappers.forEach((wrapper, index) => {
|
|
9
|
+
if (index >= 10) return;
|
|
10
|
+
|
|
11
|
+
const product = {
|
|
12
|
+
index,
|
|
13
|
+
className: wrapper.className
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const img = wrapper.querySelector('img');
|
|
17
|
+
if (img) {
|
|
18
|
+
product.img = img.getAttribute('data-src')?.substring(0, 100) || img.src?.substring(0, 100);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const parentLink = wrapper.closest('a');
|
|
22
|
+
if (parentLink) {
|
|
23
|
+
product.link = parentLink.href;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const allText = wrapper.textContent?.trim() || '';
|
|
27
|
+
product.text = allText.substring(0, 150);
|
|
28
|
+
|
|
29
|
+
const priceElements = wrapper.querySelectorAll('*');
|
|
30
|
+
for (const el of priceElements) {
|
|
31
|
+
const text = el.textContent?.trim() || '';
|
|
32
|
+
if (text.match(/[¥¥]\s*\d+/)) {
|
|
33
|
+
product.price = text;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const greatGrandParent = wrapper.parentElement?.parentElement?.parentElement;
|
|
39
|
+
if (greatGrandParent) {
|
|
40
|
+
product.greatGrandParentClass = greatGrandParent.className?.substring(0, 100);
|
|
41
|
+
const greatGrandParentText = greatGrandParent.textContent?.trim() || '';
|
|
42
|
+
product.greatGrandParentText = greatGrandParentText.substring(0, 200);
|
|
43
|
+
|
|
44
|
+
const greatGrandParentLink = greatGrandParent.querySelector('a[href*="jd"]');
|
|
45
|
+
if (greatGrandParentLink) {
|
|
46
|
+
product.link = greatGrandParentLink.href;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
result.products.push(product);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return result;
|
|
54
|
+
})()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# 场景2: 表单填写验证脚本
|
|
3
|
+
# 从 form-test.yaml 生成的脚本
|
|
4
|
+
|
|
5
|
+
set -e # 遇到错误立即退出
|
|
6
|
+
|
|
7
|
+
# 启用人工模拟模式
|
|
8
|
+
export AGENT_BROWSER_HUMAN=bezier
|
|
9
|
+
SESSION="form-verify-$(date +%s)"
|
|
10
|
+
|
|
11
|
+
# 测试页面路径
|
|
12
|
+
TEST_PAGE="file:///Users/xuyingzhou/Project/temporary/agent-browser/test-pages/form-test.html"
|
|
13
|
+
|
|
14
|
+
echo "=== 开始执行表单填写脚本 ==="
|
|
15
|
+
echo "Session: $SESSION"
|
|
16
|
+
echo "AGENT_BROWSER_HUMAN: $AGENT_BROWSER_HUMAN"
|
|
17
|
+
|
|
18
|
+
# 打开测试页面
|
|
19
|
+
echo "1. 打开表单测试页面..."
|
|
20
|
+
agent-browser --session $SESSION --allow-file-access --headed open "$TEST_PAGE"
|
|
21
|
+
agent-browser --session $SESSION wait --load networkidle
|
|
22
|
+
|
|
23
|
+
# 填写表单
|
|
24
|
+
echo "2. 填写表单..."
|
|
25
|
+
agent-browser --session $SESSION fill "#name" "测试用户"
|
|
26
|
+
agent-browser --session $SESSION fill "#email" "test@example.com"
|
|
27
|
+
agent-browser --session $SESSION fill "#password" "password123"
|
|
28
|
+
agent-browser --session $SESSION select "#country" "cn"
|
|
29
|
+
agent-browser --session $SESSION check "#agree"
|
|
30
|
+
|
|
31
|
+
# 提交表单
|
|
32
|
+
echo "3. 提交表单..."
|
|
33
|
+
agent-browser --session $SESSION click "#submitBtn"
|
|
34
|
+
|
|
35
|
+
# 等待结果显示
|
|
36
|
+
agent-browser --session $SESSION wait 500
|
|
37
|
+
|
|
38
|
+
# 验证结果
|
|
39
|
+
echo "4. 验证结果..."
|
|
40
|
+
URL=$(agent-browser --session $SESSION get url)
|
|
41
|
+
echo "当前URL: $URL"
|
|
42
|
+
|
|
43
|
+
# 检查URL是否正确
|
|
44
|
+
if [[ "$URL" == *"form-test.html"* ]]; then
|
|
45
|
+
echo "✓ URL验证成功"
|
|
46
|
+
else
|
|
47
|
+
echo "✗ URL验证失败"
|
|
48
|
+
agent-browser --session $SESSION close
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# 检查表单数据是否显示
|
|
53
|
+
RESULT=$(agent-browser --session $SESSION get text "#result")
|
|
54
|
+
if [[ "$RESULT" == *"测试用户"* ]]; then
|
|
55
|
+
echo "✓ 表单数据验证成功"
|
|
56
|
+
else
|
|
57
|
+
echo "✗ 表单数据验证失败"
|
|
58
|
+
agent-browser --session $SESSION close
|
|
59
|
+
exit 1
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
# 清理
|
|
63
|
+
echo "5. 关闭浏览器..."
|
|
64
|
+
agent-browser --session $SESSION close
|
|
65
|
+
|
|
66
|
+
echo "=== 脚本执行成功 ==="
|
|
67
|
+
exit 0
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# 场景8: 登录功能验证脚本(含验证码识别)
|
|
3
|
+
|
|
4
|
+
set -e
|
|
5
|
+
export AGENT_BROWSER_HUMAN=bezier
|
|
6
|
+
SESSION="login-verify-$(date +%s)"
|
|
7
|
+
TEST_PAGE="file:///Users/xuyingzhou/Project/temporary/agent-browser/test-pages/login-test.html"
|
|
8
|
+
|
|
9
|
+
echo "=== 开始执行登录验证脚本 ==="
|
|
10
|
+
echo "Session: $SESSION"
|
|
11
|
+
|
|
12
|
+
# 打开测试页面
|
|
13
|
+
echo "1. 打开登录测试页面..."
|
|
14
|
+
agent-browser --session $SESSION --allow-file-access --headed open "$TEST_PAGE"
|
|
15
|
+
agent-browser --session $SESSION wait --load networkidle
|
|
16
|
+
|
|
17
|
+
# 检查未登录标识
|
|
18
|
+
echo "2. 检查未登录标识..."
|
|
19
|
+
UNLOGGED=$(agent-browser --session $SESSION get text "#loggedOutIndicator")
|
|
20
|
+
if [[ "$UNLOGGED" == *"尚未登录"* ]]; then
|
|
21
|
+
echo "✓ 检测到未登录标识"
|
|
22
|
+
else
|
|
23
|
+
echo "✗ 未检测到未登录标识"
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
# 获取验证码并立即填写(使用链式命令减少延迟)
|
|
27
|
+
echo "3. 获取验证码并填写..."
|
|
28
|
+
agent-browser --session $SESSION eval --stdin <<'EOF'
|
|
29
|
+
const captcha = document.getElementById("captchaCode").textContent;
|
|
30
|
+
document.getElementById("username").value = "testuser";
|
|
31
|
+
document.getElementById("password").value = "password123";
|
|
32
|
+
document.getElementById("captcha").value = captcha;
|
|
33
|
+
"验证码: " + captcha;
|
|
34
|
+
EOF
|
|
35
|
+
|
|
36
|
+
echo "4. 提交登录..."
|
|
37
|
+
agent-browser --session $SESSION click "#loginBtn"
|
|
38
|
+
agent-browser --session $SESSION wait 500
|
|
39
|
+
|
|
40
|
+
# 验证登录结果
|
|
41
|
+
echo "6. 验证登录结果..."
|
|
42
|
+
STATUS=$(agent-browser --session $SESSION get text "#loginStatus")
|
|
43
|
+
if [[ "$STATUS" == *"登录成功"* ]]; then
|
|
44
|
+
echo "✓ 登录成功"
|
|
45
|
+
else
|
|
46
|
+
echo "✗ 登录失败: $STATUS"
|
|
47
|
+
agent-browser --session $SESSION close
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
# 检查用户信息显示
|
|
52
|
+
echo "7. 检查用户信息..."
|
|
53
|
+
USERINFO=$(agent-browser --session $SESSION get text "#userInfo")
|
|
54
|
+
if [[ "$USERINFO" == *"testuser"* ]]; then
|
|
55
|
+
echo "✓ 用户信息显示正确"
|
|
56
|
+
else
|
|
57
|
+
echo "✗ 用户信息显示错误"
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
# 清理
|
|
61
|
+
echo "8. 关闭浏览器..."
|
|
62
|
+
agent-browser --session $SESSION close
|
|
63
|
+
|
|
64
|
+
echo "=== 脚本执行成功 ==="
|
|
65
|
+
exit 0
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# 从 complex-scene-5.yaml 生成的验证脚本
|
|
3
|
+
# 用于验证录制转脚本的可靠性
|
|
4
|
+
|
|
5
|
+
set -e # 遇到错误立即退出
|
|
6
|
+
|
|
7
|
+
export AGENT_BROWSER_HUMAN=bezier
|
|
8
|
+
SESSION="verify-$(date +%s)"
|
|
9
|
+
|
|
10
|
+
# 测试页面路径
|
|
11
|
+
TEST_PAGE="file:///Users/xuyingzhou/Project/temporary/agent-browser/test-pages/complex-scene-5.html"
|
|
12
|
+
|
|
13
|
+
echo "=== 开始执行脚本 ==="
|
|
14
|
+
echo "Session: $SESSION"
|
|
15
|
+
|
|
16
|
+
# 打开测试页面
|
|
17
|
+
echo "1. 打开测试页面..."
|
|
18
|
+
agent-browser --session $SESSION --allow-file-access --headed open "$TEST_PAGE"
|
|
19
|
+
agent-browser --session $SESSION wait --load networkidle
|
|
20
|
+
|
|
21
|
+
# 执行表单填写
|
|
22
|
+
echo "2. 填写表单..."
|
|
23
|
+
agent-browser --session $SESSION fill "#username" "测试用户001"
|
|
24
|
+
agent-browser --session $SESSION fill "#email" "test@example.com"
|
|
25
|
+
agent-browser --session $SESSION fill "#comments" "这是一个自动化测试备注信息"
|
|
26
|
+
|
|
27
|
+
# 点击按钮
|
|
28
|
+
echo "3. 点击按钮..."
|
|
29
|
+
agent-browser --session $SESSION click "#btn-primary"
|
|
30
|
+
agent-browser --session $SESSION click "#btn-secondary"
|
|
31
|
+
agent-browser --session $SESSION click "#btn-success"
|
|
32
|
+
agent-browser --session $SESSION click "#btn-danger"
|
|
33
|
+
|
|
34
|
+
# 下拉选择
|
|
35
|
+
echo "4. 选择下拉选项..."
|
|
36
|
+
agent-browser --session $SESSION select "#country" "cn"
|
|
37
|
+
agent-browser --session $SESSION select "#city" "北京"
|
|
38
|
+
|
|
39
|
+
# 复选框
|
|
40
|
+
echo "5. 勾选复选框..."
|
|
41
|
+
agent-browser --session $SESSION check "#chk1"
|
|
42
|
+
agent-browser --session $SESSION check "#chk2"
|
|
43
|
+
agent-browser --session $SESSION check "#chk4"
|
|
44
|
+
|
|
45
|
+
# 单选框
|
|
46
|
+
echo "6. 选择单选项..."
|
|
47
|
+
agent-browser --session $SESSION click "#rd1"
|
|
48
|
+
|
|
49
|
+
# 计数器
|
|
50
|
+
echo "7. 点击计数器..."
|
|
51
|
+
agent-browser --session $SESSION click "#counter-increase"
|
|
52
|
+
|
|
53
|
+
# 开关
|
|
54
|
+
echo "8. 切换开关..."
|
|
55
|
+
agent-browser --session $SESSION click "#dark-mode-toggle"
|
|
56
|
+
|
|
57
|
+
# 收集数据
|
|
58
|
+
echo "9. 点击收集数据..."
|
|
59
|
+
agent-browser --session $SESSION click "#collect-data"
|
|
60
|
+
|
|
61
|
+
# 验证结果
|
|
62
|
+
echo "10. 验证结果..."
|
|
63
|
+
URL=$(agent-browser --session $SESSION get url)
|
|
64
|
+
echo "当前URL: $URL"
|
|
65
|
+
|
|
66
|
+
# 检查URL是否正确
|
|
67
|
+
if [[ "$URL" == *"complex-scene-5.html"* ]]; then
|
|
68
|
+
echo "✓ URL验证成功"
|
|
69
|
+
else
|
|
70
|
+
echo "✗ URL验证失败"
|
|
71
|
+
agent-browser --session $SESSION close
|
|
72
|
+
exit 1
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# 清理
|
|
76
|
+
echo "11. 关闭浏览器..."
|
|
77
|
+
agent-browser --session $SESSION close
|
|
78
|
+
|
|
79
|
+
echo "=== 脚本执行成功 ==="
|
|
80
|
+
exit 0
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# 场景3: 文件上传验证脚本
|
|
3
|
+
|
|
4
|
+
set -e
|
|
5
|
+
export AGENT_BROWSER_HUMAN=bezier
|
|
6
|
+
SESSION="upload-verify-$(date +%s)"
|
|
7
|
+
TEST_PAGE="file:///Users/xuyingzhou/Project/temporary/agent-browser/test-pages/upload-test.html"
|
|
8
|
+
TEST_FILE="/Users/xuyingzhou/Project/temporary/agent-browser/test-pages/upload-test.txt"
|
|
9
|
+
|
|
10
|
+
echo "=== 开始执行文件上传脚本 ==="
|
|
11
|
+
echo "Session: $SESSION"
|
|
12
|
+
|
|
13
|
+
# 打开测试页面
|
|
14
|
+
echo "1. 打开文件上传测试页面..."
|
|
15
|
+
agent-browser --session $SESSION --allow-file-access --headed open "$TEST_PAGE"
|
|
16
|
+
agent-browser --session $SESSION wait --load networkidle
|
|
17
|
+
|
|
18
|
+
# 上传文件
|
|
19
|
+
echo "2. 上传文件..."
|
|
20
|
+
agent-browser --session $SESSION upload "#fileInput" "$TEST_FILE"
|
|
21
|
+
|
|
22
|
+
# 等待上传完成
|
|
23
|
+
agent-browser --session $SESSION wait 1000
|
|
24
|
+
|
|
25
|
+
# 验证结果
|
|
26
|
+
echo "3. 验证结果..."
|
|
27
|
+
URL=$(agent-browser --session $SESSION get url)
|
|
28
|
+
if [[ "$URL" == *"upload-test.html"* ]]; then
|
|
29
|
+
echo "✓ URL验证成功"
|
|
30
|
+
else
|
|
31
|
+
echo "✗ URL验证失败"
|
|
32
|
+
agent-browser --session $SESSION close
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# 清理
|
|
37
|
+
echo "4. 关闭浏览器..."
|
|
38
|
+
agent-browser --session $SESSION close
|
|
39
|
+
|
|
40
|
+
echo "=== 脚本执行成功 ==="
|
|
41
|
+
exit 0
|