从从 google 搜索中获取链接的循环创建数据框

Create a dataframe from a loop that gets links from a google search

我有以下代码:

输入:

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 中得到这些结果。我想要的输出是这样的:

领英 脸书 Instagram 网站
https://br.linkedin.com/company/havanoficial https://www.facebook.com/Havanoficial/ https://www.instagram.com/havanoficial/ https://www.havan.com.br/

有什么建议吗?我真的很感激! :D

您可以执行以下操作:

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/