簡體   English   中英

如何在此代碼中僅使用正確的關鍵字打印鏈接?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM