首页 / 爬虫 / python58同城爬虫
python58同城爬虫
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python58同城爬虫,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1116字,纯文字阅读大概需要2分钟。
内容图文
![python58同城爬虫](/upload/InfoBanner/zyjiaocheng/713/4fdd0f0e8a184c9daa5c1b0b443cfa99.jpg)
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()
内容总结
以上是互联网集市为您收集整理的python58同城爬虫全部内容,希望文章能够帮你解决python58同城爬虫所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】