我想用python和BeautifulSoup
来抓取一个站点,但是我找不到页码,我只能抓取站点的第一页,我认为这个站点使用了Ajax,当我更改页面时,URL地址不会改变
这是网站的链接:
https://ihome.ir/sell-residential-apartment/th-tehran
这是我的代码,我想<>强>刮擦< /强>这个站点的20页,用价格、基础等细节来刮房子
import requests
from bs4 import BeautifulSoup
response = requests.get("https://ihome.ir/sell-residential-apartment/th-tehran")
soup = BeautifulSoup(response.json(), "html.parser")
prices = soup.select('.sell-value')
titles = soup.select('.title')
homes_prices = []
for home in prices:
homes_prices.append(int(''.join(filter(str.isdigit, home.getText()))))
homes_titles = []
for title in titles:
homes_titles.append(title.getText())
res = dict(zip(homes_titles, homes_prices))
for key, value in res.items():
p = str(res[key])
if len(str(res[key])) <= 2:
p += '000000000'
if len(str(res[key])) > 2:
p += '000000'
print(key.strip(), int(p))
没有必要使用
BeautifulSoup
作为您正在寻找的data
。已在JSON
目录中显示这里是
Back-End
API,从中获取数据当您查看}页以及包含
scrape
{24
项的每一页时所以它是
24 * 20
=480
,所以我将每页的结果调整为480
,并调用API
一次,比在页面上循环多次要好现在你有了一个
JSON
目录,你可以访问和提取你想要的任何东西相关问题 更多 >
编程相关推荐