【发布时间】:2019-12-01 09:44:48
【问题描述】:
你好朋友,我正在尝试获取所有数据,例如名称价格和来自此所有链接的其他数据我在 python 中获取所有 href 链接,但我不知道如何立即获取我正在尝试的所有名称和价格获取但我收到错误我只能打印此代码中的所有链接,但我需要此链接中的所有数据(名称、价格、另一个),请帮助我如何做到这一点,这是我的代码。
url='https://m.autocentrum.pl/nowe/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# To download the whole data set, let's do a for loop through all a tags
for i in range(80,len(soup.findAll('a'))+1): #'a' tags are for links
one_a_tag = soup.findAll('a')[i]
link = one_a_tag['href']
download_url = 'http://m.autocentrum.pl'+ link
# urllib.request.urlretrieve(download_url,+link[link.find("div", class_="car-offer")+1:])
# for i in range(len(soup1.findall("div"))):
# name = download_url.find("div", class_="new-car-header")[i]
# print(name)
# page = requests.get(download_url)
# soup = BeautifulSoup(page.text, 'html.parser')
# rating = soup.find_all("div", class_="car-offer") # this is the main div inside this div all data it is so how to export in csv file
# last_links = soup.find(class_='car-offer')
# last_links.decompose()
#name = soup.find(class_='new-car-header')
# last_links = download_url.find(class_='car-offer')
# last_links.decompose()
# name = download_url.find(class_='new-car-header')
# price = download_url.find(class_='mobile-car-price')
# extra = more-info
# artist_name_list_items = artist_name_list.find_all('a')
#urllib.request.urlretrieve(download_url,'./'+link[link.find('/turnstile_')+1:])
print(download_url)
time.sleep(1) #pause the code for a sec
【问题讨论】:
标签: html python-3.x web-scraping