我使用这个email_check类作为我的脚本的一部分,最近它抛出了错误。我不得不更改代码,因为它一度使用google plus,并因此抛出错误,我从下面代码中的for语句中删除了google plus,现在我得到类型错误' Type‘object is not iterable。代码如下:
from scraper.config import Config
# from scraper.google_plus import GooglePlus
from scraper.scraper import Scraper
from scraper.spokeo import Spokeo
class EmailChecker:
def __init__(self):
config = Config()
# Open instance to chromedriver
self.__scraper = Scraper()
def check_email(self, email):
config = Config()
results = {}
# for _ in (GooglePlus, Spokeo):
for _ in (Spokeo):
site = _(self.__scraper)
try:
result = site.search_for_email(email)
except Exception:
if config.debug:
raise
result = None
try:
site.logout()
except Exception:
if config.debug:
raise
pass
results[_.__name__] = result
try:
self.__scraper.driver.close()
except Exception:
pass
try:
self.__scraper.driver.quit()
except Exception:
pass
return results发布于 2020-02-05 11:26:03
(GooglePlus, Spokeo)是一个可以在for循环中迭代的元组。(Spokeo)是括号内的表达式,仅用于表示优先级。更具体的例子是,考虑(2 + 3, 1) (计算结果为(5, 1))与(2 + 3) (计算结果为5)。
为了对代码进行最小程度的更改,您可以只编写(Spokeo,)而不是(Spokeo)来拥有一个元组,尽管这是一个有点奇怪的语法。由于您不再迭代任何内容,因此可以直接删除for循环:
results = {}
_ = Spokeo # the old for was here
site = _(self.__scraper)
...但是考虑一下有一个比_更好的名字。或者直接删除该变量,显式地使用Spokeo来代替:site = Spokeo(self.__scraper)等等。
https://stackoverflow.com/questions/60068543
复制相似问题