Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x 在表中获取href_Python 3.x_Beautifulsoup_Href - Fatal编程技术网

Python 3.x 在表中获取href

Python 3.x 在表中获取href,python-3.x,beautifulsoup,href,Python 3.x,Beautifulsoup,Href,对不起,很可能以前有人问过我,但我似乎在stack/搜索引擎中找不到答案 我试图从表中提取一些数据,但是我需要获取href链接。Html格式如下: <table class="featprop results"> <tr> **1)**<td class="propname" colspan="2"><a href="/lettings-search-results?task=View&amp;itemid=136" rel="nofollow"

对不起,很可能以前有人问过我,但我似乎在stack/搜索引擎中找不到答案

我试图从表中提取一些数据,但是我需要获取href链接。Html格式如下:

<table class="featprop results">
<tr>
**1)**<td class="propname" colspan="2"><a href="/lettings-search-results?task=View&amp;itemid=136" rel="nofollow"> West Drayton</a></td>
</tr>
<tr><td class="propimg" colspan="2">

    <div class="imgcrop">
    **2)**<a href="/lettings-search-results?task=View&amp;itemid=136" rel="nofollow"><img src="content/images/1/1/641/w296/858.jpg" alt=" Ashford" width="148"/></a>


    <div class="let">&nbsp;</div>
    </div>
</td></tr>

<tr><td class="proprooms">
在上面的html中同时返回1和2,有人能帮我去掉href链接吗

for table in soup.findAll('table', {'class': 'featprop results'}):
    for tr in table.findAll('tr'):
        for a in tr.findAll('a'):
            print(a['href'])
输出:

编辑:

输出:

编辑:


这将在所选类名的元素下提供一个标记数组

result = soup.select(".featprop a");
for a in result:
    print(a['href']) 
请给出以下结果:

/lettings-search-results?task=View&itemid=136
/lettings-search-results?task=View&itemid=136

这将在所选类名的元素下提供一个标记数组

result = soup.select(".featprop a");
for a in result:
    print(a['href']) 
请给出以下结果:

/lettings-search-results?task=View&itemid=136
/lettings-search-results?task=View&itemid=136

a['href']
呢?那
a['href']
呢?谢谢!虽然这样做有效,但我找到了一些我不想要的链接,是否可以只返回以“/lettings search results”开头的链接?这样做有效,但返回了每个链接中的3个。因此,我需要努力消除重复。谢谢大家!@Maverick将所有链接放在一个集合()中,这将删除重复的链接。正在努力将其添加到集合中,您能告诉我您的意思吗?谢谢!虽然这样做有效,但我找到了一些我不想要的链接,是否可以只返回以“/lettings search results”开头的链接?这样做有效,但返回了每个链接中的3个。因此,我需要努力消除重复。谢谢大家!@Maverick将所有链接放在一个集合()中,这将删除重复的链接。正在努力将其添加到集合中,您能告诉我您的意思吗?
/lettings-search-results?task=View&itemid=136
/lettings-search-results?task=View&itemid=136