を発見された行に等しい変数の設定:キーワードとのリンクが発見されるまで私は、トラブル正しいキーワードは次のコードで発見されたリンク印刷抱えていたキーワードが
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
コードがループに成功していますしかし、それはキーワードで特定のリンクを表示しませんあなたが
for link in links:
if keyword1 in link.text and keyword2 in link.text and keyword3 in link.text:
print("LINK SCRAPED")
print(str(link.text) + "link scraped")
をしなければならない代わりに「https://properlbc.com/collections/new-arrival/products/bb1296」
を見つけたときにループを残します。 – furas