[英]How can I only print the link with correct keywords in this code?
到目前为止,这就是我所拥有的,现在我只需要输出仅是带有“ lion-double-ring”的链接,因为现在idle打印整个信息页面。 这应该循环直到找到链接并使用给定的关键字打印链接。 也许正则表达式是去这里的方法? 链接
from bs4 import BeautifulSoup
import requests
r = requests.get('walmart.com)
soup = BeautifulSoup(r.text, 'html')
links = soup.find_all('loc')
if "lion" and "double" in str(links):
print str(links)
else:
print('nothing')
from bs4 import BeautifulSoup
import requests
r = requests.get('http://shop.exclucitylife.com/sitemap_products_1.xml?from=1331122689&to=8543902145')
soup = BeautifulSoup(r.text, 'lxml')
links = soup.find_all('loc')
for link in links:
if 'lion-double-ring' in link.text:
print(link.text)
break
else:
print('nothing')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.