[英]Using BeautifulSoup to search for a tag with certain attributes, but NOT fixed attribute values
I have the following HTML that I'm trying to search via beautifulsoup: 我有以下HTML,我正尝试通过beautifulsoup搜索:
<a href="/user_details?userid=**********">
The problem is I want to pull out all links with the above format, but the userid can change. 问题是我想提取所有具有上述格式的链接,但是用户ID可以更改。 How would I go about doing that? 我将如何去做?
Thanks! 谢谢!
Would something like 会像
for link in soup.find_all('a'):
link_href = link.get('href')
if 'user_details' in link_href:
# found match
print link_href
do the trick? 绝招?
We list all a (link) urls, search for the string 'user_details' in each link, if it's found - do work with the link. 我们列出所有(链接)URL,在每个链接中搜索字符串“ user_details”(如果找到)-使用该链接。 If user_details matches something else, you could change it to something else. 如果user_details与其他内容匹配,则可以将其更改为其他内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.