我想从Flickr下载图片,到目前为止,我做到了:
import bs4, requests, re
img = requests.get('https://www.flickr.com/search/?text=nature')
img.raise_for_status()
soup = bs4.BeautifulSoup(img.text)
elem = soup.select('main div div div div')
elem[10]
<div class="view photo-list-photo-view requiredToShowOnServer awake" data-view-signature="photo-list-photo-view__UA_1__engagementModelName_photo-lite-models__excludePeople_true__id_8598154512__interactionViewName_photo-list-photo-interaction-view__isMobile_false__isOwner_false__layoutItem_1__measureAFT_true__model_1__modelParams_1__openAdvanced_false__parentContainer_1__parentSignature_photolist-47t__requiredToShowOnClient_true__requiredToShowOnServer_true__rowHeightMod_1__searchSimilar_true__searchSimilarWithTerm_false__searchTerm_nature__searchType_1__showAdvanced_true__showInteractionBarPlaceholder_false__showSort_true__showTools_true__sortMenuItems_1__unifiedSubviewParams_1__viewType_jst" style="transform: translate(277px, 191px); -webkit-transform: translate(277px, 191px); -ms-transform: translate(277px, 191px); width: 364px; height: 205px; background-image: url(//c1.staticflickr.com/9/8232/8598154512_a4e080002d.jpg)"> <div class="interaction-view"></div>
你能帮我从elem中的样式标签中得到背景图像吗?在
要提取属性,可以使用
elem[10].attrs
然后拆分字符串或使用正则表达式提取背景。在
做下面这样的事情怎么样:
部分输出:
^{pr2}$相关问题 更多 >
编程相关推荐