【发布时间】:2018-05-28 13:32:50
【问题描述】:
我有这个汤:
该网页在网格视图(16 行 x 5 列)中有公司的引用,我想检索每个引用的 url 和标题。问题是每行中的所有 5 个引用都在一个名为 row 的类中,当我抓取页面时,我只能看到每行的第一个引用,而不是全部 5 个。到目前为止,这是我的代码:
url = 'http://www.slimstock.com/nl/referenties/'
r = requests.get(url)
soup = BeautifulSoup(r.content, "lxml")
info_block = soup.find_all("div", attrs={"class": "row"})
references = pd.DataFrame(columns=['Company Name', 'Web Page'])
for entry in info_block:
try:
title = entry.find('img').get('title')
url = entry.a['href']
urlcontent = BeautifulSoup(requests.get(url).content, "lxml")
row = [{'Company Name': title, 'Web Page': url}]
references = references.append(row, ignore_index=True)
except:
pass
有没有办法解决这个问题?
【问题讨论】:
标签: python web-scraping beautifulsoup href