使用for循环尝试比较文本

2024-10-04 01:23:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有各种品牌的网址在一个数据框,我已经得到了使用自动谷歌搜索,我已经把这些网址分成几个字,并试图比较品牌名称和制造商名称与网址,以检查是否是正确的或不正确的(因为大多数公司的网址要么基于他们的品牌名称或他们的制造公司名称)

try: 
              from googlesearch import search 
except ImportError: 
              print("No module named 'google' found") 


for i in search(Brand.get_attribute("innerHTML"), tld="com", num=15, stop=1, pause=2): 
    webaddresses.append(i)

for i in search(Manufacturer.get_attribute("innerHTML"), tld="com", num=15, stop=1, pause=2): 
    webaddresses.append(i)

for i in search(Brand.get_attribute("innerHTML") and Manufacturer.get_attribute("innerHTML"), tld="com", num=15, stop=1, pause=2): 
    webaddresses.append(i)

for i in search(Brand.get_attribute("innerHTML") and Manufacturer.get_attribute("innerHTML") and "Beverage", tld="com", num=15, stop=1, pause=2): 
    webaddresses.append(i)

webaddresses = pd.DataFrame(webaddresses)
webaddresses.rename(columns = {list(webaddresses)[0]:'URL'}, inplace=True)

splitting_gurl = webaddresses['URL'].str.split(r'[.\:/?=\-&]+', expand = True)




for i in range(len(splitting_gurl.index)):
    row = splitting_gurl.loc[[i]]    
    for j in range (0,5):
        if row[[j]] == str(Brand_check) or row[[j]] == str(Manufacturer_check):
            a=webaddresses.loc[[i]]
            print(a)

以下是错误:-你知道吗

 File "<ipython-input-124-0b002229b2b7>", line 4, in <module>
if row[[j]] == str(Brand_check) or row[[j]] == str(Manufacturer_check):

File "C:\Users\Anaconda3\lib\site-packages\pandas\core\generic.py", line 1576, in __nonzero__
.format(self.__class__.__name__))

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

我只想让For循环和IF语句运行并比较单词。你知道吗


Tags: in名称comforsearchgetattributerow