赞
踩
刚学习了python,中途遇到很多问题,查了很多资料,最关键的就是要善于调试,div信息一定不要找错,下面就是我爬取租房信息的代码和运行结果:
链家的房租网站
两个导入的包
1.requests 用来过去网页内容
import time
import pymssql
import requests
from bs4 import BeautifulSoup
#https://bj.lianjia.com/zufan
完整代码如下:
import requests
import uuid
import time
from bs4 import BeautifulSoup
from src.request import send as send
from src.database import database as database
def requestHtmlData() :
conn = database.initDataConnect()
url = "https://bj.lianjia.com/zufang/pg{0}/#contentList"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43'
}
i = 1;
while(1==1):
rurl = url.replace("{0}",str(i))
print("请求地址:&
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。