from bs4 import BeautifulSoup
import urllib
r = urllib.urlopen('https://www.open2study.com/courses').read()
soup = BeautifulSoup(r)
links = soup.find('figure').find_all('img', src=True)
for link in links:
txt = open('test.txt' , "w")
link = link["src"].split("src=")[-1]
download_img = urllib.urlopen('https://www.open2study.com/courses')
txt.write(download_img.read())
txt.close()
我需要从this website刮取图像和标题。在
像这样?在
您可以直接用},而不是执行
beautifulsoup
获取{split
使用此命令可获取包含标题和图像的
div
然后使用这个来获取每个div中的标题和图像:
^{pr2}$您还可以在每次循环中打开页面(如果希望避免),只需打开一次,然后将其用于循环,如下所示:
以下是新的输出:
相关问题 更多 >
编程相关推荐