如何获得具有相同类名和属性的特定项
我要买这3件东西
April 14, 2013
580
Fort Pierce, FL
<dl class="pairsJustified">
<dt>Joined:</dt>
<dd>Apr 14, 2013</dd>
</dl>
<dl class="pairsJustified">
<dt>Messages:</dt>
<dd><a href="search/member?user_id=13302" class="concealed"
rel="nofollow">580</a></dd>
</dl>
<dl class="pairsJustified">
<dt>Location:</dt>
<dd>
<a href="misc/location-info?location=Fort+Pierce%2C+FL" target="_blank"
rel="nofollow noreferrer" itemprop="address" class="concealed">Fort
Pierce, FL</a>
你知道吗 你知道吗
这是一个很好的起点:
有很多方法可以做到这一点。稍微摆弄一下就会得到你喜欢的格式。上面的方法只是一个很好的起点,因为有很多行只有换行符列表作为输出,这是因为(看起来)用户信息块在用户有用户组图像的地方(比如亚利桑那州的特斯拉),然后
extraUserInfo
类也被用来对html块进行分组。会有更好的方法来分组基本上,response.css('.extraUserInfo')将使用类
extraUserInfo
聚合所有块,这些块似乎是保存您要查找的用户信息的块。 从那里用::text
伪选择器提取所有底层文本并解析数组如果您仔细查看html结构,这样提取它的方式会减少以后的处理工作,那么肯定有更好的方法来实现这一点,但这应该会让您走上正确的轨道。CSS选择器或xpath文档应该很有帮助
使用它们位于
<dd>
标记下,使用.find_all()
:输出:
相关问题 更多 >
编程相关推荐