Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 返回列表的差异_Python_List_Comparison - Fatal编程技术网

Python 返回列表的差异

Python 返回列表的差异,python,list,comparison,Python,List,Comparison,我似乎打赌列表旧URL和新URL之间的差异不会得到任何返回值。该脚本应该不断轮询,直到差异追加差异并返回差异。然后返回到def newresponse() 使用def定义函数,而不是调用它。永远不会调用main()和newresponse()函数。因此,旧列表和新列表将保持为空,无法显示任何差异。在底部,我分别调用每个函数,不是吗?main()newresponse()monitorchange()抱歉-没有向下滚动。昨天可能有点晚了。不管怎样:也许正是你的减法顺序没有达到你预期的效果?集合(l

我似乎打赌列表旧URL和新URL之间的差异不会得到任何返回值。该脚本应该不断轮询,直到差异追加差异并返回差异。然后返回到def newresponse()


使用def定义函数,而不是调用它。永远不会调用main()和newresponse()函数。因此,旧列表和新列表将保持为空,无法显示任何差异。

在底部,我分别调用每个函数,不是吗?main()newresponse()monitorchange()抱歉-没有向下滚动。昨天可能有点晚了。不管怎样:也许正是你的减法顺序没有达到你预期的效果?集合(l1)-集合(l2)与集合(l2)-集合(l1)不同。从文档中:“[-]返回一个新集合,集合中的元素不在其他集合中”。
from bs4 import BeautifulSoup
import requests
import time
old_urls = []
new_urls = []


def main():
  s = requests.session()
  url = s.get('https://www.sivasdescalzo.com/sitemaps/en/sitemap-1.xml')
  soup = BeautifulSoup(url.content, "html.parser")
  all_urls = soup.find_all("url")
  for url in all_urls:
     old_urls.append(url.find('loc').get_text())
def newresponse():
  s = requests.session()
  url = s.get('https://www.sivasdescalzo.com/sitemaps/en/sitemap-1.xml')
  soup2 = BeautifulSoup(url.content, "html.parser")
  all_newurls = soup2.find_all("url")
  for urls in all_newurls:
     new_urls.append(urls.find('loc').get_text())

def monitorchange():
  x = list(set(new_urls) - set(old_urls))
  print "looking for change"
  while True:
     s =requests.session()
     url = s.get('https://www.sivasdescalzo.com/sitemaps/en/sitemap-1.xml')
     soup3 = BeautifulSoup(url.content, "html.parser")
     if new_urls != old_urls:
         return x
         old_urls.append(x)
         continue
     elif url.status_code==403:
         print "bannned"
     else:
         time.sleep(60)

main()
newresponse()
monitorchange()