列表达式爬取红牛官网分公司信息
import requests
import pandas as pd
import bs4
response = requests.get("http://www.redbull.com.cn/about/branch")
main_page = bs4.BeautifulSoup(response.text,"html.parser")
company = [i.text for i in main_page.findAll("h2")]
address = [i.text for i in main_page.findAll("p",attrs={"class":"mapIco"})]
code = [i.text for i in main_page.findAll("p",attrs={"class":"mailIco"})]
tel = [i.text for i in main_page.findAll("p",attrs={"class":"telIco"})]
df = pd.DataFrame({"company":company,"address":address,"code":code,"tel":tel})
df.to_excel(excel_writer="data/redbull_list.xlsx",index=None)
df.head()
运行结果: