这是网页的HTML源代码的一部分:
<a href="http://www.abcde.com"> <img style="width:100%" src="/FileUploads/B/763846f.jpg" alt="search" title="search" /></a>
<a id="parts_img01" href="/Result?s=9&type=%E4&name=%E9"><h4 style=""><i class="fa f-c" aria-hidden="true"></i>apple</h4></a>
<a id="parts_img02" href="/Result?s=12&type=%E4&name=%E4"><h4 style=""><i class="fa f-c" aria-hidden="true"></i>banana</h4></a>
<a id="parts_img03" href="/Result?s=10&type=%E4&name=%E8"><h4 style=""><i class="fa f-c" aria-hidden="true"></i>cherry</h4></a>
<a id="parts_img07" href="/Result?s=14&type=%E4&name=%E8"><h4 style=""><i class="fa f-c" aria-hidden="true"></i>melon</h4></a>
我想提取我想要的URL,比如以/Result开头的那个? 我刚知道你可以用汤。全部找到以及汤.选择在漂亮的汤里。你知道吗
你知道吗汤。全部找到地址:
icon = soup.find_all(id = re.compile("parts_img"))
其中一个结果将成功打印:
<a href="/Result?s=9&type=%E4&name=%E9" id="parts_img01"><h4 style=""><i aria-hidden="true" class="fa f-c"></i>apple</h4></a>
你知道吗汤.选择地址:
for item in soup.select(".fa f-c"):
print(item['href'])
这不管用。。。你知道吗
有没有一种方法可以直接从html中提取URL? 我只想打印:
/Result?s=9&type=%E4&name=%E9
/Result?s=12&type=%E4&name=%E4
/Result?s=10&type=%E4&name=%E8
/Result?s=14&type=%E4&name=%E8
要在不使用regex的情况下获得相同的输出:
结果:
我在用
输出为
我认为这段代码将演示如何从给定的html中提取
href
。你知道吗相关问题 更多 >
编程相关推荐