{"id":1272,"date":"2023-07-31T13:12:36","date_gmt":"2023-07-31T05:12:36","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=1272"},"modified":"2023-07-31T13:12:36","modified_gmt":"2023-07-31T05:12:36","slug":"webclip%e5%b0%81%e8%a3%85%e6%ba%90%e7%a0%81%e6%9c%89%e4%bb%80%e4%b9%88%e4%bd%9c%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/1272\/","title":{"rendered":"webclip\u5c01\u88c5\u6e90\u7801\u6709\u4ec0\u4e48\u4f5c\u7528?"},"content":{"rendered":"

WebClip\u662f\u4e00\u79cd\u5b9e\u73b0\u7f51\u9875\u88c1\u526a\u7684\u6280\u672f\uff0c\u4e3b\u8981\u7528\u4e8e\u63d0\u53d6\u548c\u4fdd\u5b58\u7f51\u9875\u4e0a\u7684\u6307\u5b9a\u5185\u5bb9\u3002\u8fd9\u79cd\u6280\u672f\u901a\u5e38\u5e94\u7528\u4e8e\u4e66\u7b7e\u7ba1\u7406\u3001\u7b14\u8bb0\u5de5\u5177\u6216\u8005\u4e2a\u4eba\u77e5\u8bc6\u7ba1\u7406\u8f6f\u4ef6\u4e2d\u3002WebClip\u901a\u8fc7\u5c06\u7f51\u9875\u7684\u67d0\u90e8\u5206\u5185\u5bb9\u5c01\u88c5\uff0c\u4ee5\u4fbf\u4ee5\u540e\u53ef\u4ee5\u8f7b\u677e\u5730\u518d\u6b21\u67e5\u770b\u6216\u7f16\u8f91\u3002\u8fd9\u7bc7\u6587\u7ae0\u5c06\u8be6\u7ec6\u8bb2\u89e3WebClip\u7684\u539f\u7406\u53ca\u5982\u4f55\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u7684WebClip\u3002<\/p>\n

\u4e00\u3001WebClip\u539f\u7406<\/p>\n

WebClip\u7684\u539f\u7406\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u6b65\uff1a<\/p>\n

1. \u6293<\/p>\n

<\/figure>\n<\/p>\n

\u53d6\u7f51\u9875\u6e90\u7801\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u83b7\u53d6\u76ee\u6807\u7f51\u9875\u7684HTML\u6e90\u4ee3\u7801\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u4e00ipad\u600e\u4e48\u5220\u9664webclip<\/a>\u4e2a\u7b80\u5355\u7684Web\u722c\u866b\u6765\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528Python\u7684requests\u5e93\u6216Node.js\u7684axios\u5e93\u3002<\/p>\n

2. \u89e3\u6790HTML\uff1a\u83b7\u53d6\u5230\u7f51\u9875\u6e90\u4ee3\u7801\u4e4b\u540e\uff0c\u9700\u8981\u89e3\u6790HTML\uff0c\u63d0\u53d6\u6240\u9700\u7684\u4fe1\u606f\u3002\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528\u89e3\u6790HTML\u7684\u5e93\uff0c\u5982Python\u7684BeautifulSoup\u6216\u8005Node.js\u7684cheerio\u3002<\/p>\n

3. \u4f7f\u7528CSS\u9009\u62e9\u5668\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\uff1aCSS\u9009\u62e9\u5668\u662f\u4e00\u79cd\u7528\u4e8e\u67e5\u627e\u548c\u5339\u914dHTML\u5143\u7d20\u7684\u8bed\u6cd5\u3002\u5c06\u6240\u9700\u7684\u7f51\u9875\u5185\u5bb9\u7528CSS\u9009\u62e9\u5668\u5b9a\u4f4d\uff0c\u4ece\u800c\u53d6\u5f97\u60f3\u8981\u88c1\u526a\u7684\u90e8\u5206\u3002<\/p>\n

4. \u6e05\u7406\u548c\u91cd\u7ec4\u63d0\u53d6\u7684\u5185\u5bb9\uff1a\u83b7\u53d6\u5230\u76ee\u6807\u5185\u5bb9\u540e\uff0c\u53ef\u80fd\u4f1a\u5305\u542b\u4e00\u4e9b\u65e0\u5173\u7684\u6807\u7b7e\u3001\u5c5e\u6027\u548c\u6837\u5f0f\u3002\u56e0\u6b64\u9700\u8981\u5bf9\u63d0\u53d6\u7684\u5185\u5bb9\u8fdb\u884c\u6e05\u7406\uff0c\u53bb\u9664\u591a\u4f59\u7684\u4fe1\u606f\uff0c\u53ea\u4fdd\u7559\u6838\u5fc3\u5185\u5bb9\u5e76\u8fdb\u884c\u91cd\u65b0\u7ec4\u7ec7\u3002<\/p>\n

5. \u5b58\u50a8\u548c\u663e\u793a\u88c1\u526a\u7684\u5185\u5bb9\uff1a\u6700\u540e\uff0c\u5c06\u88c1\u526a\u597d\u7684\u5185\u5bb9\u5b58\u50a8\u5230\u672c\u5730\u6216\u8fdc\u7a0b\u670d\u52a1\u5668\uff0c\u5e76\u5728\u9700\u8981\u7684\u65f6\u5019\u5448\u73b0\u51fa\u6765\u3002<\/p>\n

\u4e8c\u3001\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u7684WebClip<\/p>\n

\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Python\u5b9e\u73b0\u7684\u7b80\u5355WebClip\u793a\u4f8b\uff1a<\/p>\n

1. \u5b89\u88c5\u5fc5\u8981\u7684\u5e93\uff1a<\/p>\n

“`bash<\/p>\n

pip install requests beautifulsoup4<\/p>\n

“`<\/p>\n

2. \u7f16\u5199WebClip\u4ee3\u7801\uff1a<\/p>\n

“`python<\/p>\n

import requests<\/p>\n

from bs4 import BeautifulSoup<\/p>\n

def webclip(url, css_selector):<\/p>\n

# \u83b7\u53d6\u7f51\u9875\u6e90\u4ee3\u7801<\/p>\n

response = requests.get(url)<\/p>\n

html_content = response.text<\/p>\n

# \u89e3\u6790HTML<\/p>\n

soup = BeautifulSoup(html_content, ‘html.parser’)<\/p>\n

# \u4f7f\u7528CSS\u9009\u62e9\u5668\u5b9a\u4f4d\u76ee\u6807\u5185\u5bb9<\/p>\n

target_elements = soup.select(css_selector)<\/p>\n

# \u6e05\u7406\u5e76\u91cd\u7ec4\u63d0\u53d6\u7684\u5185\u5bb9<\/p>\n

\u82f9\u679c\u514d\u7b7e\u5c01\u88c5\u6e90\u7801<\/a> cleaned_content = []<\/p>\n

for element in target_elements:<\/p>\n

cleaned_content.append(str(element))<\/p>\n<\/p>\n

# \u8fd4\u56de\u88c1\u526a\u7ed3\u679c<\/p>\n

return ”.join(cleaned_content)<\/p>\n

if __name__ == “__main__”:<\/p>\n

url = ‘https:\/\/example.com’<\/p>\n

css_selector = ‘.article-content’<\/p>\n

clipped_content = webclip(url, css_selector)<\/p>\n

print(clipped_content)<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528requests\u5e93\u83b7\u53d6\u7f51\u9875\u6e90\u4ee3\u7801\uff0c\u7136\u540e\u4f7f\u7528BeautifulSoup\u89e3\u6790HTML\uff0c\u5e76\u4f7f\u7528\u63d0\u4f9b\u7684CSS\u9009\u62e9\u5668\u6765\u5b9a\u4f4d\u76ee\u6807\u5185\u5bb9\u3002\u6700\u540e\uff0c\u6211\u4eec\u8fd4\u56de\u88c1\u526a\u540e\u7684\u5185\u5bb9\uff0c\u4f9b\u8fdb\u4e00\u6b65\u64cd\u4f5c\u3002<\/p>\n

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e2a\u793a\u4f8b\u53ea\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u529f\u80fd\u3002\u4f60\u53ef\u80fd\u9700\u8981\u6839\u636e\u5b9e\u9645\u9700\u6c42\u6269\u5c55\u8be5\u7a0b\u5e8f\uff0c\u4f8b\u5982\u652f\u6301\u591a\u79cd\u8f93\u51fa\u683c\u5f0f\uff08\u5982Markdown\u3001PDF\u7b49\uff09\uff0c\u4e3a\u88c1\u526a\u7684\u5185\u5bb9\u6dfb\u52a0\u8fc7\u6ee4\u89c4\u5219\uff0c\u4ee5\u53ca\u63d0\u4f9b\u7528\u6237\u754c\u9762\u6765\u65b9\u4fbf\u5730\u7ba1\u7406\u548c\u67e5\u770b\u88c1\u526a\u7684\u5185\u5bb9\u3002<\/p>\n

\u4ee5\u4e0a\uff0c\u6211\u4eec\u7b80\u8981\u4ecb\u7ecd\u4e86WebClip\u7684\u539f\u7406\u548c\u5b9e\u73b0\u65b9\u6cd5\u3002\u901a\u8fc7\u5bf9\u7f51\u9875\u5185\u5bb9\u7684\u88c1\u526a\u548c\u4fdd\u5b58\uff0cWebClip\u6280\u672f\u80fd\u591f\u5e2e\u52a9\u7528\u6237\u66f4\u9ad8\u6548\u5730\u7ba1\u7406\u7f51\u7edc\u8d44\u6e90\uff0c\u5e76\u4e3a\u4e2a\u4eba\u77e5\u8bc6\u7ba1\u7406\u63d0\u4f9b\u91cd\u8981\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

WebClip\u662f\u4e00\u79cd\u5b9e\u73b0\u7f51\u9875\u88c1\u526a\u7684\u6280\u672f\uff0c\u4e3b\u8981\u7528\u4e8e\u63d0\u53d6\u548c\u4fdd\u5b58\u7f51\u9875\u4e0a\u7684\u6307\u5b9a\u5185\u5bb9\u3002\u8fd9\u79cd\u6280\u672f\u901a\u5e38\u5e94\u7528\u4e8e\u4e66\u7b7e\u7ba1\u7406\u3001\u7b14\u8bb0\u5de5\u5177\u6216\u8005\u4e2a\u4eba\u77e5\u8bc6\u7ba1\u7406\u8f6f\u4ef6\u4e2d\u3002WebClip\u901a\u8fc7\u5c06\u7f51\u9875\u7684\u67d0\u90e8\u5206\u5185\u5bb9\u5c01\u88c5\uff0c\u4ee5\u4fbf\u4ee5\u540e\u53ef\u4ee5\u8f7b\u677e\u5730\u518d<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1208,289,126,149,2874],"topic":[],"class_list":["post-1272","post","type-post","status-publish","format-standard","hentry","category-iosmq","tag-webclipper","tag-289","tag-126","tag-149","tag-webclip"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/1272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=1272"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/1272\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=1272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=1272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=1272"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=1272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}