【发布时间】:2020-02-25 16:57:48
【问题描述】:
我正在尝试从列表中抓取一些列表属性网站。我编写了简单的代码来从一个 url 获取数据,但是当我尝试使用 list ['url1','url2'] 时,我什么也没有。我也在尝试使用 csv 列表,但我仍然一无所有。我检查了很多类似的主题,但结果仍然是空的。你能帮我理解怎么做吗?
'''
import lxml
import requests
import pandas as pd
from bs4 import BeautifulSoup
url = 'https://www.zillow.com/homedetails/105-Itasca-St-Boston-MA-02126/59137872_zpid/'
response = requests.get(url)
req_headers = {
'accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.8',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
with requests.Session() as s:
url
r = s.get(url, headers=req_headers)
soup = BeautifulSoup(r.content, 'lxml')
price = soup.find('span', {'class': 'ds-value'}).text
property_type = soup.find('span', {'class': 'ds-home-fact-value'}).text
address = soup.find('h1', {'class': 'ds-address-container'}).text
price, property_type, address '''
【问题讨论】:
标签: python web-scraping