网页
初始化文件。
AgentQL网页阅读器 #
基类:EventBasePydanticReader
使用或不使用 agentql 查询来抓取 URL,并以 JSON 格式返回文档。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
api_key
|
str
|
AgentQL API 密钥,请在 https://dev.agentql.com 获取 |
required |
params
|
dict
|
传递给 AgentQL API 的额外参数。请访问 https://docs.agentql.com/rest-api/api-reference 获取详细信息。 |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/agentql_web/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
load_data #
load_data(url: str, query: Optional[str] = None, prompt: Optional[str] = None) -> List[文档]
从输入目录加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
url
|
str
|
要抓取或爬取的URL。 |
required |
query
|
Optional[str]
|
用于指定抓取数据的AgentQL查询。 |
None
|
prompt
|
Optional[str]
|
您想要抓取的数据的自然语言描述。 |
None
|
params
|
Optional[dict]
|
传递给 AgentQL API 的附加参数。请访问 https://docs.agentql.com/rest-api/api-reference 获取详细信息。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/agentql_web/base.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
异步网页读取器 #
基类:EventBaseReader
异步网页阅读器。
异步读取网页内容。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
html_to_text
|
bool
|
是否将HTML转换为文本。
需要 |
False
|
limit
|
int
|
最大并发请求数。 |
10
|
dedupe
|
bool
|
如果给定列表中存在完全匹配项,则对URL进行去重 |
True
|
fail_on_error
|
bool
|
如果请求的URL未返回状态码200,该程序将引发ValueError |
False
|
workflows/handler.py 中的源代码llama_index/readers/web/async_web/base.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
aload_data
async
#
aload_data(urls: List[str]) -> List[文档]
从输入的网址加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要抓取的网址列表。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/async_web/base.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
load_data #
load_data(urls: List[str]) -> List[文档]
从输入的网址加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要抓取的网址列表。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/async_web/base.py
129 130 131 132 133 134 135 136 137 138 139 140 | |
BeautifulSoup网页阅读器 #
基类:EventBasePydanticReader
BeautifulSoup 网页阅读器。
从网页读取页面。
需要 bs4 和 urllib 软件包。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
website_extractor
|
Optional[Dict[str, Callable]]
|
网站主机名(例如 google.com)到指定如何从 BeautifulSoup 对象提取文本的函数的映射。请参阅 DEFAULT_WEBSITE_EXTRACTOR。 |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/beautiful_soup_web/base.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
class_name
classmethod
#
class_name() -> str
获取类的名称标识符。
workflows/handler.py 中的源代码llama_index/readers/web/beautiful_soup_web/base.py
157 158 159 160 | |
load_data #
load_data(urls: List[str], custom_hostname: Optional[str] = None, include_url_in_text: Optional[bool] = True) -> List[文档]
从网址加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要抓取的网址列表。 |
required |
custom_hostname
|
Optional[str]
|
在网站通过自定义URL(例如Substack博客)显示的情况下,强制使用特定主机名 |
None
|
include_url_in_text
|
Optional[bool]
|
在文档文本中包含参考网址 |
True
|
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/beautiful_soup_web/base.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
浏览器基础网页阅读器 #
基类:EventBaseReader
BrowserbaseWebReader。
使用托管在Browserbase上的无头浏览器加载预渲染的网页。
依赖于 browserbase 包。
从 https://browserbase.com 获取您的API密钥
workflows/handler.py 中的源代码llama_index/readers/web/browserbase_web/base.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
lazy_load_data #
lazy_load_data(urls: Sequence[str], text_content: bool = False, session_id: Optional[str] = None, proxy: Optional[bool] = None) -> Iterator[文档]
从URL加载页面。
workflows/handler.py 中的源代码llama_index/readers/web/browserbase_web/base.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
FireCrawl网页阅读器 #
基类:EventBasePydanticReader
使用 Firecrawl.dev 将网址转换为LLM可访问的Markdown格式。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
api_key
|
str
|
Firecrawl API 密钥。 |
required |
api_url
|
Optional[str]
|
Firecrawl 部署的可选基础 URL |
None
|
mode
|
Optional[str]
|
加载器运行的模式。默认为"crawl"。 选项包括"scrape"(单网址)、 "crawl"(所有可访问的子页面)、 "map"(映射所有可访问的子页面)、 "search"(搜索内容),以及 "extract"(使用提示从网址提取结构化数据)。 |
'crawl'
|
params
|
Optional[dict]
|
传递给 Firecrawl API 的参数。 |
None
|
示例包括爬虫选项。 更多详情请访问:https://docs.firecrawl.dev/sdks/python
workflows/handler.py 中的源代码llama_index/readers/web/firecrawl_web/base.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
load_data #
load_data(url: Optional[str] = None, query: Optional[str] = None, urls: Optional[List[str]] = None) -> List[文档]
从输入目录加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
url
|
Optional[str]
|
要抓取或爬取的URL。 |
None
|
query
|
Optional[str]
|
要搜索的查询。 |
None
|
urls
|
Optional[List[str]]
|
提取模式下的URL列表。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
如果提供了无效的参数组合。 |
workflows/handler.py 中的源代码llama_index/readers/web/firecrawl_web/base.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
超浏览器网页阅读器 #
基类:EventBaseReader
超浏览器网页阅读器。
使用可选参数配置内容提取来抓取或爬取网页。
需要 hyperbrowser 包。
从 https://app.hyperbrowser.ai/ 获取您的API密钥。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
api_key
|
Optional[str]
|
Hyperbrowser API 密钥,可设置为环境变量 |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/hyperbrowser_web/base.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
lazy_load_data #
lazy_load_data(urls: List[str], operation: Literal['scrape', 'crawl'] = 'scrape', params: Optional[Dict] = {}) -> Iterable[文档]
懒加载文档。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
待抓取或爬取的网址列表 |
required |
operation
|
Literal['scrape', 'crawl']
|
要执行的操作。可以是 "scrape" 或 "crawl" |
'scrape'
|
params
|
Optional[Dict]
|
用于抓取或爬取的可选参数。有关支持的参数的更多信息,请访问 https://docs.hyperbrowser.ai/reference/sdks/python/scrape#start-scrape-job-and-wait 或 https://docs.hyperbrowser.ai/reference/sdks/python/crawl#start-crawl-job-and-wait |
{}
|
workflows/handler.py 中的源代码llama_index/readers/web/hyperbrowser_web/base.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
alazy_load_data
async
#
alazy_load_data(urls: Sequence[str], operation: Literal['scrape', 'crawl'] = 'scrape', params: Optional[Dict] = {}) -> AsyncIterable[文档]
异步懒加载文档。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
Sequence[str]
|
待抓取或爬取的网址列表 |
required |
operation
|
Literal['scrape', 'crawl']
|
要执行的操作。可以是 "scrape" 或 "crawl" |
'scrape'
|
params
|
Optional[Dict]
|
用于抓取或爬取的可选参数。有关支持的参数的更多信息,请访问 https://docs.hyperbrowser.ai/reference/sdks/python/scrape#start-scrape-job-and-wait 或 https://docs.hyperbrowser.ai/reference/sdks/python/crawl#start-crawl-job-and-wait |
{}
|
workflows/handler.py 中的源代码llama_index/readers/web/hyperbrowser_web/base.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
知识库网页阅读器 #
基类:EventBaseReader
知识库阅读器。
使用 Playwright 从知识库/帮助中心抓取并读取文章。
已在 Zendesk 和 Intercom CMS 上测试通过,可能也适用于其他系统。
可在无头模式下运行,但可能会被 Cloudflare 拦截。为保险起见,建议使用有头模式运行。
偶尔会出现超时情况,若发生只需增加默认超时时间即可。
需要安装 playwright 软件包。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
root_url
|
str
|
知识库的基础URL,不带尾部斜杠 例如 'https://support.intercom.com' |
required |
link_selectors
|
List[str]
|
在爬取过程中用于查找文章链接的CSS选择器列表 例如 ['.article-list a', '.article-list a'] |
required |
article_path
|
str
|
该域名下文章的URL路径,以便爬虫知道何时停止 例如 '/articles' |
required |
title_selector
|
Optional[str]
|
用于查找文章标题的CSS选择器 例如:'.article-title' |
None
|
subtitle_selector
|
Optional[str]
|
用于查找文章副标题/描述的CSS选择器 例如 '.article-subtitle' |
None
|
body_selector
|
Optional[str]
|
用于定位文章正文的CSS选择器 例如 '.article-body' |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/knowledge_base/base.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
load_data #
load_data() -> List[文档]
从知识库加载数据。
workflows/handler.py 中的源代码llama_index/readers/web/knowledge_base/base.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
scrape_article #
scrape_article(browser: Any, url: str) -> Dict[str, str]
抓取单个文章链接。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
browser
|
Any
|
一个 Playwright Chromium 浏览器。 |
required |
url
|
str
|
要抓取的文章URL。 |
required |
返回:
| 类型 | 描述 |
|---|---|
Dict[str, str]
|
Dict[str, str]: 文章属性与其值的映射关系。 |
workflows/handler.py 中的源代码llama_index/readers/web/knowledge_base/base.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
get_article_urls #
get_article_urls(browser: Any, root_url: str, current_url: str, max_depth: int = 100, depth: int = 0) -> List[str]
递归遍历知识库以查找文章列表。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
browser
|
Any
|
一个 Playwright Chromium 浏览器。 |
required |
root_url
|
str
|
知识库的根URL。 |
required |
current_url
|
str
|
当前正在抓取的URL。 |
required |
max_depth
|
int
|
爬虫的最大递归层级 |
100
|
depth
|
int
|
当前深度级别 |
0
|
返回:
| 类型 | 描述 |
|---|---|
List[str]
|
List[str]: 找到的文章URL列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/knowledge_base/base.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
主内容提取阅读器 #
基类:EventBaseReader
MainContentExtractor 网页阅读器。
从网页读取页面。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
text_format
|
str
|
文本的格式。默认为 "markdown"。
需要 |
'markdown'
|
workflows/handler.py 中的源代码llama_index/readers/web/main_content_extractor/base.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
load_data #
load_data(urls: List[str]) -> List[文档]
从输入目录加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要抓取的网址列表。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/main_content_extractor/base.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
新闻文章阅读器 #
基类:EventBaseReader
简单的新闻文章阅读器。
从网络读取新闻文章并使用 newspaper 库进行解析。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
text_mode
|
bool
|
是否加载内容的文本版本或HTML版本(默认=True)。 |
True
|
use_nlp
|
bool
|
是否使用自然语言处理提取额外的摘要和关键词(默认=True)。 |
True
|
newspaper_kwargs
|
Any
|
传递给 newspaper.Article 的额外关键字参数。请参阅 https://newspaper.readthedocs.io/en/latest/user_guide/quickstart.html#article |
{}
|
workflows/handler.py 中的源代码llama_index/readers/web/news/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
load_data #
load_data(urls: List[str]) -> List[文档]
从新闻文章网址列表中加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
用于加载新闻文章的网址列表。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/news/base.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
Oxylabs网页阅读器 #
基类:EventBasePydanticReader
使用 Oxylabs 网页抓取 API 抓取任意网站,并以 Markdown 格式获取结果。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
username
|
str
|
Oxylabs API 用户名。 |
required |
password
|
str
|
Oxylabs API 密码。 |
required |
示例
.. code-block:: python from llama_index.readers.web.oxylabs_web.base import OxylabsWebReader
reader = OxylabsWebReader(
username=os.environ["OXYLABS_USERNAME"], password=os.environ["OXYLABS_PASSWORD"]
)
docs = reader.load_data(
[
"https://sandbox.oxylabs.io/products/1",
"https://sandbox.oxylabs.io/products/2"
],
{
"parse": True,
}
)
print(docs[0].text)
workflows/handler.py 中的源代码llama_index/readers/web/oxylabs_web/base.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
aload_data
async
#
aload_data(urls: list[str], additional_params: Optional[Dict[str, Any]] = None) -> List[文档]
从URL异步加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
list[str]
|
要加载的URL列表。 |
required |
additional_params
|
Optional[Dict[str, Any]]
|
爬虫参数字典,如此处所述 |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/oxylabs_web/base.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
load_data #
load_data(urls: list[str], additional_params: Optional[Dict[str, Any]] = None) -> List[文档]
从网址加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
list[str]
|
要加载的URL列表。 |
required |
additional_params
|
Optional[Dict[str, Any]]
|
爬虫参数字典,如此处所述 |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/oxylabs_web/base.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
可读性网页阅读器 #
基类:EventBaseReader
可读性网页加载器。
从完全渲染的网页中提取相关信息。 在处理过程中,始终假设用作数据源的网页包含文本内容。
- 加载页面并等待其渲染完成。(playwright)
- 注入 Readability.js 以提取主要内容。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
proxy
|
Optional[str]
|
代理服务器。默认为无。 |
None
|
wait_until
|
Optional[Literal['commit', 'domcontentloaded', 'load', 'networkidle']]
|
等待页面加载完成。默认为"domcontentloaded"。 |
'domcontentloaded'
|
text_splitter
|
TextSplitter
|
文本分割器。默认为无。 |
None
|
normalizer
|
Optional[Callable[[str], str]]
|
文本规范化器。默认为 nfkc_normalize。 |
required |
workflows/handler.py 中的源代码llama_index/readers/web/readability_web/base.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
async_load_data
async
#
async_load_data(url: str) -> List[文档]
从URL渲染并加载数据内容。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
url
|
str
|
要抓取的URL。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/readability_web/base.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
scrape_page
async
#
scrape_page(browser: Browser, url: str) -> Dict[str, str]
抓取单个文章链接。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
browser
|
Any
|
一个 Playwright Chromium 浏览器。 |
required |
url
|
str
|
要抓取的文章URL。 |
required |
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
Ref |
Dict[str, str]
|
https://github.com/mozilla/readability |
title |
Dict[str, str]
|
文章标题; |
content |
Dict[str, str]
|
经过处理的文章内容的HTML字符串; |
textContent |
Dict[str, str]
|
文章文本内容,已移除所有HTML标签; |
length |
Dict[str, str]
|
文章长度,以字符数表示; |
excerpt |
Dict[str, str]
|
文章描述,或内容简短摘录; |
byline |
Dict[str, str]
|
作者元数据; |
dir |
Dict[str, str]
|
内容方向; |
siteName |
Dict[str, str]
|
网站名称。 |
lang |
Dict[str, str]
|
内容语言 |
workflows/handler.py 中的源代码llama_index/readers/web/readability_web/base.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
RSS阅读器 #
基类:EventBasePydanticReader
RSS阅读器。
从RSS订阅源读取内容。
workflows/handler.py 中的源代码llama_index/readers/web/rss/base.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
load_data #
load_data(urls: List[str]) -> List[文档]
从RSS源加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要加载的RSS网址列表。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/rss/base.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
RSS新闻阅读器 #
基类:EventBaseReader
RSS新闻阅读器。
从RSS订阅源读取新闻内容,并使用NewsArticleReader进行解析。
workflows/handler.py 中的源代码llama_index/readers/web/rss_news/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
load_data #
load_data(urls: List[str] = None, opml: str = None) -> List[文档]
从RSS订阅源或OPML文件加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要加载的RSS网址列表。 |
None
|
opml
|
str
|
OPML文件的URL或字符串或字节形式的OPML内容。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/rss_news/base.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
Scrapfly阅读器 #
基类:EventBasePydanticReader
使用 Scrapfly.io 将网址转换为可供大语言模型访问的 Markdown 格式。
参数: api_key: Scrapfly API密钥。 scrape_config: Scrapfly ScrapeConfig对象。 ignore_scrape_failures: 是否在失败时继续执行。 urls: 要抓取的URL列表。 scrape_format: 抓取结果格式(markdown或text) 更多详细信息,请访问:https://scrapfly.io/docs/sdk/python
workflows/handler.py 中的源代码llama_index/readers/web/scrapfly_web/base.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
load_data #
load_data(urls: List[str], scrape_format: Literal['markdown', 'text'] = 'markdown', scrape_config: Optional[dict] = None) -> List[文档]
从网址加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
List[str]): 要抓取的URL列表。 |
required |
scrape_config
|
Optional[dict]
|
Optional[dict]: ScrapFly 抓取配置对象的字典。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
如果未提供URL。 |
workflows/handler.py 中的源代码llama_index/readers/web/scrapfly_web/base.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
Scrapy网页阅读器 #
基类:EventBasePydanticReader
Scrapy 网页阅读器。
从网页读取页面。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
project_path
|
Optional[str]
|
用于加载项目设置(包含中间件和管道)的Scrapy项目路径。
项目路径应包含 |
''
|
metadata_keys
|
Optional[List[str]]
|
用作从抓取项目中提取文档元数据的键列表。默认为 []。 |
[]
|
keep_keys
|
bool
|
是否在项目中保留元数据键。 默认为 False。 |
False
|
workflows/handler.py 中的源代码llama_index/readers/web/scrapy_web/base.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
load_data #
load_data(spider: Union[Spider, str]) -> List[文档]
从输入蜘蛛加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
spider
|
Union[Spider, str]
|
用于爬取的Scrapy爬虫类或项目中的爬虫名称。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 从网页中提取的文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/scrapy_web/base.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
简易网页阅读器 #
基类:EventBasePydanticReader
简易网页阅读器。
从网页读取页面。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
html_to_text
|
bool
|
是否将HTML转换为文本。
需要 |
False
|
metadata_fn
|
Optional[Callable[[str], Dict]]
|
一个接收URL并返回元数据字典的函数。 默认为None。 |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/simple_web/base.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
load_data #
load_data(urls: List[str]) -> List[文档]
从输入目录加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要抓取的网址列表。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/simple_web/base.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
站点地图阅读器 #
基类:EventBaseReader
用于网络的异步站点地图阅读器。
根据网站的站点地图文件读取网页内容。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
sitemap_url
|
string
|
站点地图 XML 文件的路径。例如:https://gpt-index.readthedocs.io/sitemap.xml |
required |
html_to_text
|
bool
|
是否将HTML转换为文本。
需要 |
False
|
limit
|
int
|
最大并发请求数。 |
10
|
workflows/handler.py 中的源代码llama_index/readers/web/sitemap/base.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
蜘蛛网阅读器 #
基类:EventBasePydanticReader
抓取URL数据并返回可供大语言模型使用的数据,使用Spider.cloud。
必须安装Python包spider-client并拥有Spider API密钥。
详情请参阅https://spider.cloud。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
api_key
|
str
|
Spider API密钥,请在 https://spider.cloud 获取 |
None
|
mode
|
Mode
|
"抓取"网址(默认)或"爬取"网址并跟踪所有子页面。 |
'scrape'
|
params
|
dict
|
传递给 Spider API 的额外参数。 |
None
|
workflows/handler.py 中的源代码llama_index/readers/web/spider_web/base.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
Trafilatura网页阅读器 #
基类:EventBasePydanticReader
Trafilatura 网页阅读器。
从网页读取页面。
需要 trafilatura 包。
workflows/handler.py 中的源代码llama_index/readers/web/trafilatura_web/base.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
class_name
classmethod
#
class_name() -> str
获取类的名称标识符。
workflows/handler.py 中的源代码llama_index/readers/web/trafilatura_web/base.py
19 20 21 22 | |
load_data #
load_data(urls: List[str], include_comments=True, output_format='txt', include_tables=True, include_images=False, include_formatting=False, include_links=False, show_progress=False, no_ssl=False, **kwargs) -> List[文档]
从网址加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
List[str]
|
要抓取的网址列表。 |
required |
include_comments
|
bool
|
在输出中包含注释。默认为 True。 |
True
|
output_format
|
str
|
输出格式。默认为 'txt'。 |
'txt'
|
include_tables
|
bool
|
在输出中包含表格。默认为 True。 |
True
|
include_images
|
bool
|
在输出中包含图像。默认为 False。 |
False
|
include_formatting
|
bool
|
在输出中包含格式。默认为 False。 |
False
|
include_links
|
bool
|
在输出中包含链接。默认为 False。 |
False
|
show_progress
|
bool
|
显示进度条。默认为 False |
False
|
no_ssl
|
bool
|
绕过SSL验证。默认为False。 |
False
|
kwargs
|
|
{}
|
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 文档列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/trafilatura_web/base.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
非结构化URL加载器 #
基类:EventBaseReader
使用unstructured加载HTML文件的加载器。
workflows/handler.py 中的源代码llama_index/readers/web/unstructured_web/base.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
load_data #
load_data() -> List[文档]
加载文件。
workflows/handler.py 中的源代码llama_index/readers/web/unstructured_web/base.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
全站阅读器 #
基类:EventBaseReader
用于网站的广度优先搜索网页抓取工具。
该类提供使用广度优先搜索算法抓取整个网站的功能。 它从给定的基础URL开始导航网页,跟踪符合指定前缀的链接。
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
prefix |
str
|
用于聚焦抓取操作的URL前缀。 |
max_depth |
int
|
BFS算法的最大深度。 |
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
prefix
|
str
|
用于抓取的URL前缀。 |
required |
max_depth
|
int
|
广度优先搜索的最大深度。默认为10。 |
10
|
uri_as_id
|
bool
|
是否使用URI作为文档ID。默认为False。 |
False
|
workflows/handler.py 中的源代码llama_index/readers/web/whole_site/base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
setup_driver #
setup_driver()
设置用于Chrome的Selenium WebDriver。
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
WebDriver |
Chrome WebDriver 的一个实例。 |
workflows/handler.py 中的源代码llama_index/readers/web/whole_site/base.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
load_data #
load_data(base_url: str) -> List[文档]
使用广度优先搜索算法从基础URL加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
base_url
|
str
|
开始抓取的基础URL。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
List[Document]: 已抓取文档的列表。 |
workflows/handler.py 中的源代码llama_index/readers/web/whole_site/base.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Zyte网页阅读器 #
基类:EventBasePydanticReader
使用 Zyte api 从URL加载文本。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
api_key
|
str
|
Zyte API 密钥。 |
required |
mode
|
Literal['article', 'html', 'html-text']
|
确定如何提取文本作为页面内容。 它可以采用以下值之一:'html', 'html-text', 'article' |
'article'
|
n_conn
|
int
|
这是要使用的最大并发请求数。 |
15
|
**download_kwargs
|
Optional[Dict[str, Any]]
|
任何要传递的额外下载参数。 参见:https://docs.zyte.com/zyte-api/usage/reference.html |
None
|
示例
.. 代码块:: python
from llama_index.readers.web import ZyteWebReader
reader = ZyteWebReader(
api_key="ZYTE_API_KEY",
)
docs = reader.load_data(
urls=["<url-1>", "<url-2>"],
)
Zyte-API 参考文档
https://www.zyte.com/zyte-api/
workflows/handler.py 中的源代码llama_index/readers/web/zyte_web/base.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
ZenRows网页阅读器 #
基类:EventBasePydanticReader
ZenRows 网页阅读器。
使用 ZenRows 通用爬虫 API 读取网页,具备以下高级功能: - 动态内容的 JavaScript 渲染 - 反机器人绕过 - 支持地理位置的高级住宅代理 - 自定义请求头和会话管理 - 使用 CSS 选择器进行高级数据提取 - 多种输出格式(HTML、Markdown、文本、PDF) - 截图功能
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
api_key
|
str
|
ZenRows API密钥。请访问 https://app.zenrows.com/register 获取 |
required |
js_render
|
Optional[bool]
|
启用无头浏览器以支持 JavaScript 渲染。默认值为 False。 |
required |
js_instructions
|
Optional[str]
|
在页面上执行自定义 JavaScript 以与元素进行交互。 |
required |
premium_proxy
|
Optional[bool]
|
使用住宅IP绕过反机器人保护。默认值为False。 |
required |
proxy_country
|
Optional[str]
|
设置用于请求的IP所在国家(需要高级代理)。 |
required |
session_id
|
Optional[int]
|
为多个请求保持相同的IP地址,最长可达10分钟。 |
required |
custom_headers
|
Optional[Dict[str, str]]
|
在您的请求中包含自定义标头以模拟浏览器行为。 |
required |
wait_for
|
Optional[str]
|
等待特定的CSS选择器出现在DOM中后再返回内容。 |
required |
wait
|
Optional[int]
|
页面加载后等待固定的毫秒数。 |
required |
block_resources
|
Optional[str]
|
阻止特定资源(图像、字体等)加载。 |
required |
response_type
|
Optional[Literal['markdown', 'plaintext', 'pdf']]
|
将HTML转换为其他格式。 |
required |
css_extractor
|
Optional[str]
|
使用CSS选择器提取特定元素(JSON格式)。 |
required |
autoparse
|
Optional[bool]
|
自动从HTML中提取结构化数据。默认为False。 |
required |
screenshot
|
Optional[str]
|
捕获页面首屏截图。 |
required |
screenshot_fullpage
|
Optional[str]
|
捕获整页截图。 |
required |
screenshot_selector
|
Optional[str]
|
使用CSS选择器捕获特定元素的屏幕截图。 |
required |
original_status
|
Optional[bool]
|
返回目标页面的原始HTTP状态码。默认为False。 |
required |
allowed_status_codes
|
Optional[str]
|
即使目标页面因指定状态码而失败,仍返回内容。 |
required |
json_response
|
Optional[bool]
|
以JSON格式捕获网络请求。默认为False。 |
required |
screenshot_format
|
Optional[Literal['png', 'jpeg']]
|
在截图时选择 png 或 jpeg 格式。 |
required |
screenshot_quality
|
Optional[int]
|
对于JPEG格式,请将质量设置为1到100之间。 |
required |
outputs
|
Optional[str]
|
指定要从抓取的HTML中提取哪些数据类型。 |
required |
workflows/handler.py 中的源代码llama_index/readers/web/zenrows_web/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
validate_css_extractor
classmethod
#
validate_css_extractor(v)
如果提供了 css_extractor,请验证其是否为有效的 JSON。
workflows/handler.py 中的源代码llama_index/readers/web/zenrows_web/base.py
137 138 139 140 141 142 143 144 145 146 | |
validate_proxy_country
classmethod
#
validate_proxy_country(v)
验证 proxy_country 是否为两位字母的国家代码。
workflows/handler.py 中的源代码llama_index/readers/web/zenrows_web/base.py
148 149 150 151 152 153 154 | |
class_name
classmethod
#
class_name() -> str
获取类的名称标识符。
workflows/handler.py 中的源代码llama_index/readers/web/zenrows_web/base.py
164 165 166 167 | |
load_data #
load_data(urls: Union[str, List[str]], extra_params: Optional[Dict] = None, **kwargs) -> List[文档]
使用 ZenRows API 从 URL 加载数据。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
urls
|
Union[str, List[str]]
|
单个URL字符串或要抓取的URL列表 |
required |
extra_params
|
Optional[Dict]
|
此特定请求的附加参数 |
None
|
**kwargs
|
额外的关键字参数(用于兼容性) |
{}
|
返回:
| 类型 | 描述 |
|---|---|
List[文档]
|
包含抓取内容和元数据的文档对象列表 |
workflows/handler.py 中的源代码llama_index/readers/web/zenrows_web/base.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
选项: 成员:- AgentQLWebReader - AsyncWebPageReader - BeautifulSoupWebReader - BrowserbaseWebReader - FireCrawlWebReader - HyperbrowserWebReader - KnowledgeBaseWebReader - MainContentExtractorReader - NewsArticleReader - OlostepWebReader - OxylabsWebReader - ReadabilityWebPageReader - RssNewsReader - RssReader - ScrapflyReader - ScrapyWebReader - SimpleWebPageReader - SitemapReader - SpiderReader - TrafilaturaWebReader - UnstructuredURLLoader - WholeSiteReader - ZenRowsWebReader