我第二亞歷克斯關於合法性說,但你可以如果您使用請求和bs4模仿Ajax請求,也可以獲取字體:
In [16]: import requests
In [17]: from bs4 import BeautifulSoup
In [18]: data = {
....: 'seed': '24',
....: "text": "Pangrams",
....: "src": "pangram.auto",
....: "size": "72",
....: "fg": "000000",
....: "bg": "ffffff",
....: "goodies": "_2x:0",
....: "w": "720",
....: "i[]": ["fort-foundry/gin/regular,,720", "fort-foundry/gin/oblique,,720", "fort-foundry/gin/rough,,720",
....: "fort-foundry/gin/rough-oblique,,720", "fort-foundry/gin/round,,720","fort-foundry/gin/round-oblique,,720",
....: "fort-foundry/gin/lines,,720", "fort-foundry/gin/lines-oblique,,720"],
....: "showimgs": "true"}
In [19]: js = requests.post("http://www.myfonts.com/ajax-server/testdrive_new-ajax.php", data=data).json()
In [20]:
In [20]: urls = [img["src"] for img in BeautifulSoup("".join(js.values()),"lxml").find_all("img")]
In [21]: pp(urls)
['//samples.myfonts.net/a_91/u/af/5e840d069d35f2c8e5f7077bae7b1e.gif',
'//samples.myfonts.net/e_91/u/d6/1d63ad993299d182ae19eddb2c41e1.gif',
'//samples.myfonts.net/e_92/u/7c/15b8e24e4b077ae3b1c7a614afa8b5.gif',
'//samples.myfonts.net/b_92/u/ce/63dffdda8581fc83f6fe20874714e7.gif',
'//samples.myfonts.net/e_91/u/51/e8b7a0b5cccb2abf530b05e1d3fb04.gif',
'//samples.myfonts.net/b_91/u/6f/a5f870c719dcf9961e753b9f4afd7e.gif',
'//samples.myfonts.net/b_92/u/7c/94d652e4f146801e3c81f694898e07.gif',
'//samples.myfonts.net/b_91/u/47/39fa3ab779cabd1068abbca7ce98c5.gif']
只有你需要通過的是i []:值,其餘的可以用來改變尺寸,背景顏色等。
所以如果你不在乎改變bg,fg或size並使用bs4和請求獲取所有名稱,可以從search-result-item
類中獲取字體名稱,然後使用以下命令構建Ajax請求:
In [1]: import requests
In [2]: from bs4 import BeautifulSoup
In [3]: r = requests.get("http://www.myfonts.com/fonts/fort-foundry/gin/")
In [4]: soup = BeautifulSoup(r.content, "lxml")
# creates fort-foundry/gin/regular,,720" etc..
In [5]: fonts = ["{},,720".format(a["href"].strip("/").split("/", 1)[1])
for a in soup.select("div .search-result-item h4 a[href]")]
In [6]: data = {
...: "i[]": fonts
...: }
In [7]: js = requests.post("http://www.myfonts.com/ajax-server/testdrive_new-ajax.php", data=data).json()
In [8]: urls = [img["src"] for img in BeautifulSoup("".join(js.values()),"lxml").select("img[src]")]
In [9]:
In [9]: from pprint import pprint as pp
In [10]: pp(urls)
['//samples.myfonts.net/b_91/u/06/64bdafe9368dd401df4193a7608028.gif',
'//samples.myfonts.net/b_92/u/06/b8ad49c563d310a97147d8220f55ab.gif',
'//samples.myfonts.net/a_91/u/e7/8f84ce98f19e3f91ddc15304d636e7.gif',
'//samples.myfonts.net/e_91/u/71/9769a1ab626429d63d3c779fcaa3d7.gif',
'//samples.myfonts.net/b_92/u/65/fe416f15ea94b1f8603ddc675fd638.gif',
'//samples.myfonts.net/b_91/u/5d/3ced9e71910bc411a0d76316d18df1.gif',
'//samples.myfonts.net/e_92/u/cd/0df987a72bb0a43cba29b38c16b7a5.gif',
'//samples.myfonts.net/e_91/u/88/3f80a1108fd0a075c69b09e9c21a8d.gif']