嗨,我想从下面的网站上抓取公司链接https://www.unpri.org/directory/。但是我的代码总是返回None而不是href,这是我的代码。我试着在这里搜索,但似乎找不到其他有同样问题的人。在
这是我的原始代码
from splinter import Browser
import bs4 as bs
import os
import time
import csv
url = 'https://www.unpri.org/directory/'
path = os.getcwd() + "/chromedriver"
executable_path = {'executable_path': path}
browser = Browser('chrome', **executable_path)
browser.visit(url)
source = browser.html
soup = bs.BeautifulSoup(source,'lxml')
for url in soup.find_all('div',class_="col-xs-8 col-md-9"):
print(url.get('href', None))
直到所有三个按钮的链接都显示在Selenium上。然后它将整个页面的html保存到一个名为
page_source.html
的文件中。在然后用BeautifulSoup解析html,保存到dict(
{org_name: url}
),然后转储到名为organisations.json
的json文件中。在只花了不到4分钟,所有的链接都显示出来了。如果您想节省一些时间,这里有一个link to the gist显示这个源代码,}。在
page_source.html
和{相关问题 更多 >
编程相关推荐