【问题标题】:Create a dataframe from a loop that gets links from a google search从从谷歌搜索中获取链接的循环中创建一个数据框
【发布时间】:2021-10-16 18:42:58
【问题描述】:

我有以下代码:

在:

from googlesearch import search
query_list = ["Linkedin","Facebook","Instagram", "site oficial"]

company_name = input("Please provide the stock name:")

for j in query_list:
for i in search(company_name+j, tld='com.br', lang='pt-br', num=1, start=0, stop=1, 
pause=1.0):
    print (i)

输出:

https://br.linkedin.com/company/havanoficial
https://www.facebook.com/Havanoficial/
https://www.instagram.com/havanoficial/
https://www.havan.com.br/

问题是我需要将这些结果放在具有 4 个不同列的 DataFrame 中。我想要的输出是这样的:

Linkedin Facebook Instagram Website
https://br.linkedin.com/company/havanoficial https://www.facebook.com/Havanoficial/ https://www.instagram.com/havanoficial/ https://www.havan.com.br/

有什么建议吗?对此,我真的非常感激! :D

【问题讨论】:

    标签: python dataframe google-search


    【解决方案1】:

    您可以执行以下操作:

    out = [
    'https://br.linkedin.com/company/havanoficial/',
    'https://www.facebook.com/Havanoficial/',
    'https://www.instagram.com/havanoficial/',
    'https://www.havan.com.br/',
    ]
    
    df = pd.DataFrame(out)
    df = df.T
    df.columns = query_list
    

    结果:

    In [38]: df                                                                                                                                          
    Out[38]: 
                                           Linkedin                                Facebook                                Instagram               site oficial
    0  https://br.linkedin.com/company/havanoficial  https://www.facebook.com/Havanoficial/  https://www.instagram.com/havanoficial/  https://www.havan.com.br/
    

    【讨论】:

      猜你喜欢
      • 2011-07-07
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多