博客雲 2024-09-01 05:29 采纳率: 60%
浏览 7
已结题

爬虫使用beautifulsoup的find方法怎么把HTML的网址单独提取出来

爬虫使用beautifulsoup的find方法怎么把HTML的网址单独提取出来?
我提取出来的是这样的,后面不知道怎么提取出网址

import requests
from lxml import etree
from bs4 import BeautifulSoup

url = 'https://tieba.baidu.com/f?kw=%E9%BB%91%E7%A5%9E%E8%AF%9D&ie=utf-8&tab=album' 
response = requests.get(url).text
soup = BeautifulSoup(content, 'html.parser')
img_all = soup.find_all('img', attrs={'width': '232', 'height': '174'})
for img_one in img_all:
    
    print(img_one)


<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D0%2C0%2C789%2C591%3Bwh%3D227%2C170%3B/sign=a949c214bbfaaf5190acdbffb164b8de/658f99c69f3df8dcb652e5a38b11728b47102852.jpg?tbpicau=2024-09-12-05_1fb06ffba3447613e6ddf38b8a381106" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D0%2C0%2C1032%2C773%3Bwh%3D227%2C170%3B/sign=6888c03fbedcd100d9d3a2614fbb6b20/954abbd9bc3eb13560b5dd89e01ea8d3fd1f4457.jpg?tbpicau=2024-09-12-05_67cb8c846ae520af939014020f532657" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D220%2C0%2C1478%2C1107%3Bwh%3D227%2C170%3B/sign=25689f1a48f41bd5ce1cb2b46ce8b3fb/98f169124954092385221b4fd458d109b3de497d.jpg?tbpicau=2024-09-12-05_939ac1fb7ccb10edb10006b4a50f89d7" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D238%2C0%2C1442%2C1080%3Bwh%3D227%2C170%3B/sign=dbbfb5dd9700baa1ae631dfb7a228a2a/85afd4c7a7efce1bd994b0fbe951f3deb48f6501.jpg?tbpicau=2024-09-12-05_c595878f0ae5b34873f888dcff392b74" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D220%2C0%2C1478%2C1107%3Bwh%3D227%2C170%3B/sign=1cac6a7ed82f07084b4a7040d4168aa9/c14797fbe6cd7b89052b42b2492442a7d9330e79.jpg?tbpicau=2024-09-12-05_645dec5266c9c880e57181ac9d4d5c42" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D238%2C0%2C1442%2C1080%3Bwh%3D227%2C170%3B/sign=5ba0fefc1466d0166a56c468aa19e73f/430e3059d109b3defef999598abf6c81800a4c7a.jpg?tbpicau=2024-09-12-05_56e4be02336494de538ebd2a7dcbca70" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D0%2C0%2C1767%2C1323%3Bwh%3D227%2C170%3B/sign=3701f898ef014c080d7472e5374b2e38/8b6fa50928381f303701f898ef014c086e06f0ad.jpg?tbpicau=2024-09-12-05_efd28d06e4f05beb31c525949008ddf2" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D76%2C0%2C2003%2C1500%3Bwh%3D227%2C170%3B/sign=471edb5109c2d562e6478aadda26a6c3/5656cf234f4a20a4b80549f6d6529822720ed0ae.jpg?tbpicau=2024-09-12-05_08e4bfc38bd882f1a6c5fb8e6710e550" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D319%2C0%2C1282%2C960%3Bwh%3D227%2C170%3B/sign=c7fb6e72cdd4b31ce473cefbbae51646/67cbe511b912c8fc4ed883fcba039245d688219d.jpg?tbpicau=2024-09-12-05_352cad8f5dbb776b7ce101f596da199a" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D379%2C0%2C1162%2C870%3Bwh%3D227%2C170%3B/sign=f2ebd924fa315c6057da31afb082fc2a/feb8b84d510fd9f9c53f2058632dd42a2834a49c.jpg?tbpicau=2024-09-12-05_6dca9b931bfd883d642709a81721c3b1" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D236%2C0%2C1446%2C1083%3Bwh%3D227%2C170%3B/sign=0127d70b764e251ff6b8beb89ab4fa21/69992f1101e93901612cf80f3dec54e736d19692.jpg?tbpicau=2024-09-12-05_c2737e49c506027a4c009a4343a032ab" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D318%2C0%2C1923%2C1440%3Bwh%3D227%2C170%3B/sign=8ead70c39362853586af8861addc47fe/444f7bf8d72a605930d0eb2b6e34349b023bba84.jpg?tbpicau=2024-09-12-05_fbb7df8814247b8ff3f471e508110d7c" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D0%2C0%2C988%2C740%3Bwh%3D227%2C170%3B/sign=5682ae17bbfaaf5190acdbffb164b8de/afe16f10728b4710218bfbfd85cec3fdfc032318.jpg?tbpicau=2024-09-12-05_9878e2ad693bc5adda7208b8ff9290c9" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D0%2C0%2C670%2C502%3Bwh%3D227%2C170%3B/sign=aa4f801dc101a18be4a4480fa31f2b38/444f7bf8d72a605904b6e72b6e34349b033bba1a.jpg?tbpicau=2024-09-12-05_ec8b691f9bdc1e04b38fd5c367663342" width="232"/>
<img height="174" src="https://tiebapic.baidu.com/forum/crop%3D0%2C0%2C996%2C746%3Bwh%3D227%2C170%3B/sign=fbd2a1599709b3defff0be28f18f40b1/948b9bdab6fd52667d8a3a25ed18972bd407361b.jpg?tbpicau=2024-09-12-05_0d3d15f6e6b4b598fe71f58023abef21" width="232"/>

展开全部

  • 写回答

1条回答 默认 最新

  • 吃苹果的牛顿顿 2024-09-01 10:11
    关注

    四妹: 臭猴子,get方法就可以提取到src属性

    import requests
    from bs4 import BeautifulSoup
    
    url = 'https://tieba.baidu.com/f?kw=%E9%BB%91%E7%A5%9E%E8%AF%9D&ie=utf-8&tab=album'
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'html.parser')
    img_all = soup.find_all('img', attrs={'width': '232', 'height': '174'})
    for img_one in img_all:
        # 提取src
        img_src = img_one.get('src')
        print(img_src)
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 9月9日
  • 已采纳回答 9月2日
  • 创建了问题 9月1日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部