【发布时间】:2017-05-16 04:57:36
【问题描述】:
我希望能够刮出链接列表。由于 html 的结构方式,我不能直接使用 BeautifulSoup。
start_list = soup.find_all(href=re.compile('id='))
print(start_list)
[<a href="/movies/?id=actofvalor.htm"><b>Act of Valor</b></a>,
<a href="/movies/?id=actionjackson.htm"><b>Action Jackson</b></a>]
我只想提取 href 信息。我正在考虑某种过滤器,我可以将所有粗体标签放入一个列表中,然后将它们从另一个包含上述信息的列表中过滤出来。
start_list = soup.find_all('a', href=re.compile('id='))
start_list_soup = BeautifulSoup(str(start_list), 'html.parser')
things_to_remove = start_list_soup.find_all('b')
这个想法是能够遍历 things_to_remove 并从 start_list 中删除所有出现的内容
【问题讨论】:
-
发布你想要的输出。
标签: python-3.x web-scraping beautifulsoup filtering