如何使用python从crunchbase访问公司的描述?

时间:2017-01-16 00:31:28

标签: python beautifulsoup urllib

我确实尝试过使用beautifulSoup,但没有成功。

import urllib2
import tldextract
from BeautifulSoup import BeautifulSoup
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
u2 =  urllib2.urlopen("https://www.crunchbase.com/organization/facebook#/entity")
soup = BeautifulSoup(u2)
access_response_2 = soup.find('dl',class = "definition-list-container")

1 个答案:

答案 0 :(得分:-1)

我认为你不能连接&使用urllib2解析cruchabse网站。上次我尝试他们抛出 416 HTTP错误。然后我尝试使用urllib2请求设置useragent,正确的HTTP标头和cookie值,但它也失败了。

请改用selenium。 有了它,您将能够连接到cruchbase页面&解析。连接到目标页面后,使用selenium附带的解析器解析它,或者也可以使用beautifulSoup

示例代码:

from selenium import webdriver
driver= webdriver.Firefox()
driver.get('https://www.crunchbase.com/organization/facebook#/entity')

用selenium解析

driver.find_element_by_class_name('definition-list-container')

或使用BeautifulSoup解析

soup = BeautifulSoup(driver.page_source, "html.parser")
soup.find('dl',{ 'class' : "definition-list-container"})