Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 刮削a';href';从a<;span>;a中没有类<;部门>;_Python_Web Scraping - Fatal编程技术网

Python 刮削a';href';从a<;span>;a中没有类<;部门>;

Python 刮削a';href';从a<;span>;a中没有类<;部门>;,python,web-scraping,Python,Web Scraping,我对使用BeatifulSoup和python非常陌生,我在尝试在范围内获取a href时遇到了一些困难,但它没有类。。下面的代码部分来自一个phpbb论坛,我可以删除所有的href,但由于某些原因,我无法理解如何获取范围内的内容 <div class="col-md-48 post-text" data-topic="6693rw38" data-forum="2"> <br> <br> <a

我对使用BeatifulSoup和python非常陌生,我在尝试在范围内获取a href时遇到了一些困难,但它没有类。。下面的代码部分来自一个phpbb论坛,我可以删除所有的href,但由于某些原因,我无法理解如何获取范围内的内容

<div class="col-md-48 post-text" data-topic="6693rw38" data-forum="2">
<br>
<br>
<a href="http://imgshare.net/img-5ba3dt3ad8a24.html" target="_blank" class="postlink" rel="nofollow"></a>
<br>
<br>
<a href="http://imgshare.net/img-5baefr1a51a49.html" target="_blank" class="postlink" rel="nofollow"></a>
<br>
<br>
<span>
    <a href="https://k2s.cc/file/5c745ce5g9193/toyota.mp4" target="_blank">https://k2s.cc/file/5c745ce5g9193/toyota.mp4</a>
</span>
<br>
<br>
<a href="http://imgshare.net/img-5ba34d1q805b8.html" target="_blank" class="postlink" rel="nofollow"></a>
<br>
<br>
<span>
    <a href="https://k2s.cc/file/b28gr283ef76e/ford.mp4" target="_blank">https://k2s.cc/file/b28gr283ef76e/ford.mp4</a>
</span>

谢谢大家

您可能正在寻找类似的内容(使用css选择器):

输出:

['http://imgshare.net/img-5ba3dt3ad8a24.html',
 'http://imgshare.net/img-5baefr1a51a49.html',
 'http://imgshare.net/img-5ba34d1q805b8.html']
编辑:

要获取这些节点的文本内容,请使用

all_links2 = [s.text for s in soup.select('div.col-md-48 > span > a[href]')]
all_links2
输出:

['https://k2s.cc/file/5c745ce5g9193/toyota.mp4',
 'https://k2s.cc/file/b28gr283ef76e/ford.mp4']

谢谢你的快速回答。。您的代码绝对有意义,但出于某种原因,它返回空列表。。另外,我想了解的是span-->a-->href..@AtApi中的内容答案中的输出是您问题中示例html中
节点中的内容。至于为什么你会得到空列表-你可能需要在你的问题中添加实际的url来回答这个问题。我明白了,但我试图从第10行和第18行的范围内抓取href“例如”和“谢谢你的帮助”help@AtApi我懂了;您要查找的是文本节点,而不是
链接
属性值。见编辑。谢谢你,伙计!我仍然得到一个空列表,但我认为你把我放在了正确的轨道上,我会更好地检查html,看看为什么我会得到空列表,但我真的很感谢你的帮助!!!!,
all_links2 = [s.text for s in soup.select('div.col-md-48 > span > a[href]')]
all_links2
['https://k2s.cc/file/5c745ce5g9193/toyota.mp4',
 'https://k2s.cc/file/b28gr283ef76e/ford.mp4']