要爬取HTML中script标签里的URL值,可以使用Python的BeautifulSoup库来解析HTML并提取所需的URL值。

下面是一个简单的示例代码:

from bs4 import BeautifulSoup

html = """
<html>
<body>
    <script src='https://example.com/script1.js'></script>
    <script src='https://example.com/script2.js'></script>
    <script src='https://example.com/script3.js'></script>
</body>
</html>
"""

soup = BeautifulSoup(html, 'html.parser')
script_tags = soup.find_all('script')

for script in script_tags:
    url = script.get('src')
    print(url)

解析HTML文档后,使用find_all('script')方法找到所有的script标签。然后使用get('src')方法获取script标签的src属性值,即URL值。

运行以上代码将输出:

https://example.com/script1.js
https://example.com/script2.js
https://example.com/script3.js

请注意,这只是一个简单的示例,实际情况可能更复杂。你可能需要根据HTML文档的结构和具体需求来调整代码。

Python爬取HTML中的script标签URL值

原文地址: https://www.cveoy.top/t/topic/pInC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录