尝试使用python抓取此网站,但无法获得所需的d

2024-07-04 08:21:16 发布

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

我想在这个网站上找到公司名称https://siftery.com/microsoft-outlook 基本上它列出了一些使用微软Outlook的公司。 我使用了beauthoulsoup,requests,urllib和urllib2,但是我仍然没有得到使用微软Outlook的公司的名字,甚至在网站的第一页也没有。在

我写的代码如下-

r = requests.get('http://siftery.com/microsoft-outlook')

print(str(r.content))
f=open('abc.txt','w')
f.write(r.content)
f.close()

有意思的部分输出是-

({“name”:“Marketing”,“handle”:“Marketing”,“categories”:[{“name”:“Marketing Automation”,“handle”:“Marketing Automation”,“external_id”:“tgJ k7v4j-wV”,“parent_handle”:null,“categories”:[{“name”:“Marketing Automation Platforms”,“handle”:“Marketing Automation平台”,“external_id”:“tgJLE9aHoLdneT”,“parent_handle”:“营销自动化”}

beauthulsoup也给了我相同的输出,其他库也是如此。 好像“外部的”身份证“是在哪里的公司名称?我不确定。我还尝试使用gedit手动查找一家公司的名称,例如Acxiom,但找不到任何匹配项。在


Tags: name名称com网站公司contentrequestsmarketing
2条回答

数据可以直接作为JSON提供。您可以使用请求来获得:

import requests

r = requests.post('https://siftery.com/product-json/microsoft-outlook')
data = r.json()['content']
companies = data['companies']
for company in companies:
    print(companies[company]['name'])

输出

^{pr2}$

您可能需要调查其他类别的信息:

>>> data.keys()
[u'product', u'vendor', u'users', u'group_members', u'companies', u'customers', u'other_categories', u'current_user', u'page_info', u'portfolio_products', u'primary_category', u'metadata']

该站点使用javascript加载信息,这意味着当您执行请求时,DOM将不带信息呈现,因为它是异步加载的,对于像这样的站点,您应该使用selenium。在

注: 在构建scraper之前,您应该查看站点是否有一个api或端点,并禁用CORS,在这种情况下,您可以通过post请求来获取信息https://siftery.com/product-json/<product_name>

相关问题 更多 >

    热门问题