[英]Img scraping using bs4 and selenium
I am trying to scrape some img files from IG using selenium and bs4. 我正在尝试使用selenium和bs4从IG抓取一些img文件。 I have this following script to do it, it seems to work fine, but eventually I'd like it to just print img src
, a sample: https://scontent-lax3-2.cdninstagram.com/vp/2592f6b07f88bfc4bfdf6d73400a04b8/5BA6E998/t51.2885-15/s640x640/sh0.08/e35/28752330_1972627949433283_1816022201220988928_n.jpg
and download images later. 我使用以下脚本来执行此操作,它似乎工作正常,但最终我希望它仅打印img src
,即示例: https://scontent-lax3-2.cdninstagram.com/vp/2592f6b07f88bfc4bfdf6d73400a04b8/5BA6E998/t51.2885-15/s640x640/sh0.08/e35/28752330_1972627949433283_1816022201220988928_n.jpg
: https://scontent-lax3-2.cdninstagram.com/vp/2592f6b07f88bfc4bfdf6d73400a04b8/5BA6E998/t51.2885-15/s640x640/sh0.08/e35/28752330_1972627949433283_1816022201220988928_n.jpg
并稍后下载图像。 But for now I would need some help to just print that img src link without the tags and extras. 但是现在,我需要一些帮助来仅打印该img src链接而无需标签和其他功能。 Thanks for the advice. 谢谢你的建议。
Code: 码:
import requests
from bs4 import BeautifulSoup
import selenium.webdriver as webdriver
url = ('https://www.instagram.com/kitties/')
driver = webdriver.Firefox()
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'lxml')
img_url = soup.find_all('img', class_='_2di5p')
print img_url
Just print out the src
of the found images. 刚打印出来的src
找到的图像。
imgs= soup.find_all('img', class_='_2di5p')
for img in imgs:
img_url=img["src"]
print img_url
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.