我正试图刮这个桌子:https://www.coingecko.com/en/coins/recently_added?page=1
这是我的密码:
import requests
from bs4 import BeautifulSoup
import csv
root_url = "https://www.coingecko.com/en/coins/recently_added"
html = requests.get(root_url)
soup = BeautifulSoup(html.text, 'html.parser')
paging = soup.find("div",{"class":"row no-gutters tw-flex flex-column flex-lg-row tw-justify-end mt-2"}).find("ul",{"class":"pagination"}).find_all("a")
start_page = paging[1].text
last_page = paging[len(paging)-2].text
#
# outfile = open('gymlookup.csv','w', newline='')
# writer = csv.writer(outfile)
# writer.writerow(["Name", "Address", "Phone"])
pages = list(range(1,int(last_page)+1))
for page in pages:
url = 'https://www.coingecko.com/en/coins/recently_added?page=%s' %(page)
html = requests.get(url)
soup = BeautifulSoup(html.text, 'html.parser')
#print(soup.prettify())
print ('Processing page: %s' %(page))
coins = soup.findAll("div",{"class":"coingecko-table"})
for element in coins:
coin = element.find(class_='coin-name text-left tablesorter-header tablesorter-headerUnSorted')
price = element.find(class_='price text-right sorter-numeric tablesorter-header tablesorter-headerUnSorted')
print(coin,price)
# hr = element.find('change1h').text
# last_added = element.find('last_added').text
# writer.writerow([coin, price, hr,last_added])
#
# outfile.close()
print('Done')
印刷品(硬币、价格)无法印刷任何东西。不知道为什么,欢迎任何帮助:)
下面是从一个页面获取数据进行分页的代码,您已经这样做了,所以只需要另一个循环
输出:
只需使用
pandas
获取表数据以下是方法:
输出:
您可以使用
Selenium
:这将输出:
相关问题 更多 >
编程相关推荐