BeautifulSoup4获取“ li a”,其中li内无文本

时间:2019-02-27 00:53:46

标签: python html beautifulsoup

我需要帮助,以从网站获取一些特定的锚点。网站具有这种结构

<li>
  This has a link
  <a href="#">1st link</a>
</li>
<li>
  <a href="#">2nd link</a>
</li>
<li>
  This also has a link
  <a href="#">1st link</a>
</li>

我只想获取在li中没有文本的锚点。 使用BeautifulSoup最简单的方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以分析address: "Somewhere along PTI road, Effurun. Delta State" name: "Effurun" region: "South-South" 的元素以确定是否仅存在router.get('/:zipcode/:type/:rad', function (req, res) { const rad = req.params.rad; const zip = req.params.zipcode; let zips = zipcodes.radius(zip, rad); zips.push(zip); let type; if(req.params.type === 'bartenders') { type = 0; } else { type = 1; } const params = { 'type': type, 'zips': zips }; function userGroup(type, zip) { return new Promise(resolve => { connection.query(`SELECT * FROM bt9.users WHERE zip = ${zip} AND type = ${type} AND display = 1`, function (err, result) { if(err) throw err; resolve(result); }); }); } async function getUsers(params) { let userList = []; for (i = 0; i < params.zips.length; i++) { const users = await userGroup(params.type, params.zips[i]); for (u = 0; u < users.length; u++) { userList.push(users[u]); } } return userList; } function sendUsers(callback) { getUsers(params).then( res => { callback(null, res) }) } sendUsers(function(err, result) { if(err) throw err; res.send(result) }) });个对象:

soup.contents

输出:

soup