articles = contents.find_all('article')
for article in articles:
titles=article.find('div',{"class":"featured"})
print(titles)
这将输出为
<div class="featured" style="background-image: url(https://therecipecritic.com/wp-content/uploads/2018/02/Mint-Oreo-Cheesecake-1-of-1-350x500.jpg)"> <a href="https://therecipecritic.com/2018/02/mint-oreo-cheesecake/" rel="bookmark"><span class="readpost">View the Recipe</span></a></div>
在这里我如何获得 a
元素的href答案 0 :(得分:0)
你很亲密。您可以通过访问查找href
属性返回的结果的内置__getitem__
方法来访问a
:
print(titles.find('a')['href'])
答案 1 :(得分:0)
您需要先访问@IBAction func didPinch(_ pinchGR: UIPinchGestureRecognizer) {
self.view.layer.sublayers![0].setAffineTransform(
self.view.layer.sublayers![0].affineTransform().scaledBy(
x:pinchGR.scale, y:pinchGR.scale))
pinchGR.scale = 1.0;
}
标记,然后像使用字典一样访问它的a
属性:
href
答案 2 :(得分:0)
使用Python对猫进行皮肤修复的许多方法。我是这样做的......
wsHREF = wsArticle.find("<<tag>>", re.compile("<<classname>>.*")).attrs['href']
其中&#39; wsArticle
&#39;是我的元素节点的BSoup对象,<<tag>>
是要查找的HTML标记,<<classname>>
是您要搜索的class
,但我使用通配符查找以...开头的所有内容。 .. myclass ......等等。