溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

python58同城爬蟲(chóng)

發(fā)布時(shí)間:2020-10-22 17:03:52 來(lái)源:網(wǎng)絡(luò) 閱讀:416 作者:wx5d72071a58c07 欄目:編程語(yǔ)言
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('h3',class_="title")
for title in titles:
        href=title.find('a')['href']
        print(href)
        href_list.append(href)

csv_file=open('58同城酒店轉(zhuǎn)讓項(xiàng)目信息.csv','w+',newline='',encoding='utf-8')
writer=csv.writer(csv_file)
file_head=['項(xiàng)目名','聯(lián)系人','聯(lián)系電話','信息','地址']
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('h2',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()
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI