58同城python_python58同城爬虫

import requests,time,csv

from bs4 import BeautifulSoup

href_list=[]

url='https://hz.58.com/lvguanbinguan'

headers={

'user-agent':

}

params={

'PGTID': '0d306b32-0004-f711-87c6-3e3cb7371c0d',

'ClickID': '2'

}

res=requests.get(url,headers=headers,params=params)

soup=BeautifulSoup(res.text,'html.parser')

titles=soup.find_all('h2',class_="title")

for title in titles:

href=title.find('a')['href']

print(href)

href_list.append(href)

csv_file=open('58同城酒店转让项目信息.csv','w+',newline='',encoding='utf-8')

writer=csv.writer(csv_file)

file_head=['项目名','联系人','联系电话','信息','地址']

writer.writerow(file_head)

hotel_list=[]

for href in href_list:

url=href

headers={

'user-agent':

}

res=requests.get(url,headers=headers)

soup=BeautifulSoup(res.text,'lxml')

title=soup.find('h1',class_="c_000 f20").text

name=soup.find(class_="poster-name").text

phone=soup.find('p',class_="phone-num").text

detail=soup.find('p',class_="house_basic_title_info").text

address=soup.find('p',class_="p_2").text

print(title,phone)

hotel_list.append([title,name,phone,detail,address])

time.sleep(1)

for row in hotel_list:

writer.writerow(row)

csv_file.close()

文章来源: blog.51cto.com,作者:wx5d72071a58c07,版权归原作者所有,如需转载,请联系作者。

原文链接:https://blog.51cto.com/14534896/2439531

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值