我無法打印正確的關鍵字在下面的代碼中發現的鏈接:設置變量等於行,其中關鍵字發現
import urllib2
from random import randint
import time
from lxml import etree
from time import sleep
a = requests.get('http://properlbc.com/sitemap.xml')
#time.sleep(1)
scrape = BeautifulSoup(a.text, 'lxml')
linkz = scrape.find_all('loc')
for linke in linkz:
if "products" in linke.text:
sitemap = str(linke.text)
break
while True:
# sleep(randint(4,6))
keyword1 = "properlbc"
keyword2 = "products"
keyword3 = "bb1296"
r = requests.get(sitemap)
# time.sleep(1)
soup = BeautifulSoup(r.text, 'lxml')
links = soup.find_all('loc')
for link in links:
while (keyword1 in link.text and keyword2 in link.text and keyword3 in link.text):
continue
print("LINK SCRAPED")
print(str(link.text) + "link scraped")
break
的代碼是成功的循環,直到用關鍵字鏈接被發現但它不打印帶有關鍵字的具體環節,它打印的,而不是「https://properlbc.com/collections/new-arrival/products/bb1296」
。 – furas