这是我的代码。在这里,我试图一一提取元素,但没有得到相关答案。有人可以帮帮我吗。
from bs4 import BeautifulSoup
import requests
####/// for data
r = requests.get('https://www.yelu.in/company/911002/abntravels')
soup = BeautifulSoup(r.text,'lxml')
data = soup.find('div',{"id":"company_item"})
for info1 in data.find_all('div',class_='info')[0]:
c_name = info1.find('span',{'id':'company_name'})
print(c_name)
for info2 in data.find_all('div',class_='info')[1]:
c_add = info2.find('div',class_='text location')
print(c_add)
for info3 in data.find_all('div',class_='info')[2]:
phone = info3.find('div',class_='text phone')
print(phone)
for info4 in data.find_all('div',class_='info')[3]:
mob = info4.find('div',class_='text')
print(mob.text)
for info5 in data.find_all('div',class_='info')[4]:
Fax = info5.find('div',class_='text')
print(Fax.text)
for info6 in data.find_all('div',class_='info')[5]:
Website = info6.find('div',class_='text weblinks')
print(Website.text)
for info7 in data.find_all('div',class_='info')[6]:
Year = info7.findNextSibling('span',class_='label')
print(year)
for info8 in data.find_all('div',class_='info')[7]:
employees = info8.findNextSibling('span',class_='label')
print(employees)
for info9 in data.find_all('div',class_='info')[7]:
manager = info9.findNextSibling('span',class_='label')
print(manager)
我正在获取None前 3 个元素。从下一个元素,我收到此错误:AttributeError: 'NoneType' object has no attribute 'text'。对于最后 3 个元素,又是AttributeError错误。
相关分类