195
Points
Questions
37
Answers
38
-
Asked on July 17, 2020 in Python.
You can just use BeautifulSoup
from bs4 import BeautifulSoup as bs xml = ''' <text font="TimesNewRomanPSMT" bbox="72.024,707.275,78.769,718.315" colourspace="DeviceGray" ncolour="0" size="11.040">T</text> <text font="TimesNewRomanPSMT" bbox="78.769,707.275,84.289,718.315" colourspace="DeviceGray" ncolour="0" size="11.040">h</text> <text font="TimesNewRomanPSMT" bbox="84.289,707.275,87.359,718.315" colourspace="DeviceGray" ncolour="0" size="11.040">i</text> <text font="TimesNewRomanPSMT" bbox="87.359,707.275,91.653,718.315" colourspace="DeviceGray" ncolour="0" size="11.040">s</text> <text font="TimesNewRomanPSMT" bbox="91.697,707.275,94.457,718.315" colourspace="DeviceGray" ncolour="0" size="11.040"> </text> <text font="TimesNewRomanPSMT" bbox="94.336,707.275,97.405,718.315" colourspace="DeviceGray" ncolour="0" size="11.040">i</text> <text font="TimesNewRomanPSMT" bbox="97.449,707.275,101.744,718.315" colourspace="DeviceGray" ncolour="0" size="11.040">s</text> ''' soup = bs(xml, 'lxml') soup = soup.find_all('text') [print(i.text, end="") for i in soup]
- 479 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in XML.
Your code is running correctly here. See my result file. I’ve also changed the explicitRoot key to true at Parser creation and it also changed correctly.
{ "BIREYSEL": { "bkBildirimdeBulunanFinansKurulusuSayisi": "2", "bkEnEskTakibeAlinmaTarihi": "", "bkExclusionCode": "", "bkGecikmedekiToplamHesapSayisi": "0", "bkGeciktirdigiBakiyeToplami": "0", "bkHesapDokumuBeans": { "bkHesap": { "element": [ { "bkAcilisTarihi": "20190716", "bkDovizKodu": "TL", "bkEnSonGuncellemeTarihi": "20190915", "bkGecikmedekiBakiye": "0", "bkHesaptakiKonumu": "1", "bkKapanisTarihi": { "element": "" }, "bkKayitReferansNo": "7027461580078B", "bkKrediKartiTaksitliBakiye": "000000263", "bkKrediTuru": "23", "bkKrediTutariLimiti": "12250", "bkKurumRumuzu": "A", "bkLimitKullanimOrani": "0.09", "bkOdemePerformansiTarihcesi": "000", "bkSiraNo": "1", "bkTakibeAlinmaBakiyesi": "0", "bkTakipTarihi": "", "bkToplamBakiye": "1026", "bkToplamGeciktirilmisOdemeSayisi": "00", "bkTuketiciKredisiTaksitSayisi": "", "bkTuketiciKredisiTaksitTutari": "" }, { "bkAcilisTarihi": "20110914", "bkDovizKodu": "TL", "bkEnSonGuncellemeTarihi": "20190913", "bkGecikmedekiBakiye": "0", "bkHesaptakiKonumu": "1", "bkKapanisTarihi": { "element": "" }, "bkKayitReferansNo": "5670737591250I", "bkKrediKartiTaksitliBakiye": "000000000", "bkKrediTuru": "23", "bkKrediTutariLimiti": "3500", "bkKurumRumuzu": "B", "bkLimitKullanimOrani": "0.00", "bkOdemePerformansiTarihcesi": "000000000000000000", "bkSiraNo": "2", "bkTakibeAlinmaBakiyesi": "0", "bkTakipTarihi": "", "bkToplamBakiye": "0", "bkToplamGeciktirilmisOdemeSayisi": { "element": "" }, "bkTuketiciKredisiTaksitSayisi": "", "bkTuketiciKredisiTaksitTutari": "" } ] } }, "bkKrediNotu": "1369", "bkKrediNotuSebepKodu1": "12", "bkKrediNotuSebepKodu2": "06", "bkKrediNotuSebepKodu3": "09", "bkKrediNotuSebepKodu4": "17", "bkMevcutEnUzunGecikmeSuresi": "0", "bkSonKrediKullandirimTarihi": "20190716", "bkSorguNo": "72626513", "bkTakibiDevamEdenKrediSayisi": "0", "bkTakipBildirimdeBulunanFinansKurulusuSayisi": "0", "bkToplamKrediliHesapSayisi": "2", "bkToplamLimit": "15750", "bkToplamRisk": "1026", "bkToplamTakibeAlinmisKrediSayisi": "0", "bkToplamTakipBakiyesi": "0", "bkWorstPaymetStatusEver": "0", "krsSonucu": "000", "krsVeriBulunduMu": "true" }, "TICARI": { "krmSonucu": "1", "krmVeriBulunduMu": "false", "tkBildirimdeBulunanFinansKurulusuSayisi": "0", "tkEnEskiTakipTarihi": "", "tkEnGuncelLimitTahsisTarihi": "", "tkEnYakinTakipTarihi": "", "tkGecikmedekiHesapSayisi": "0", "tkGecikmisBakiyeToplami": "0", "tkGuncelKrediBakiyesiToplami": "0", "tkIlkKrediKullandirimTarihi": "", "tkLimitRiskBeans": "", "tkSonKrediKullandirimTarihi": "", "tkTakFaktoringBildirimDonemi": "", "tkTakFaktoringCalistigiBankVeDigerMaliKurulusSayisi": "0", "tkTakFaktoringFaizReeskontKomisyon": "0", "tkTakFaktoringFaizTahakkukuKomisyon": "0", "tkTakFaktoringKrediLimiti": "0", "tkTakFaktoring_12_24_Ay_Vadeli": "0", "tkTakFaktoring_1_12_Ay_Vadeli": "0", "tkTakFaktoring_24_Ay_Vadeli": "0", "tkTakLeasingBildirimDonemi": "", "tkTakLeasingCalistigiBankVeDigerMaliKurulusSayisi": "0", "tkTakLeasingFaizReeskontKomisyon": "0", "tkTakLeasingFaizTahakkukuKomisyon": "0", "tkTakLeasingKrediLimiti": "0", "tkTakLeasing_12_24_Ay_Vadeli": "0", "tkTakLeasing_1_12_Ay_Vadeli": "0", "tkTakLeasing_24_Ay_Vadeli": "0", "tkTakibeAlindigiTarihtekiRiskTutarlariToplami": "0", "tkTakipHesabiBildirimdeBulunanFinansKurulusuSayisi": "0", "tkTokFaktoringBildirimDonemi": "", "tkTokFaktoringCalistigiBankVeDigerMaliKurulusSayisi": "0", "tkTokFaktoringFaizReeskontKomisyon": "0", "tkTokFaktoringFaizTahakkukuKomisyon": "0", "tkTokFaktoringKrediLimiti": "0", "tkTokFaktoring_12_24_Ay_Vadeli": "0", "tkTokFaktoring_1_12_Ay_Vadeli": "0", "tkTokFaktoring_24_Ay_Vadeli": "0", "tkTokLeasingBildirimDonemi": "", "tkTokLeasingCalistigiBankVeDigerMaliKurulusSayisi": "0", "tkTokLeasingFaizReeskontKomisyon": "0", "tkTokLeasingFaizTahakkukuKomisyon": "0", "tkTokLeasingKrediLimiti": "0", "tkTokLeasing_12_24_Ay_Vadeli": "0", "tkTokLeasing_1_12_Ay_Vadeli": "0", "tkTokLeasing_24_Ay_Vadeli": "0", "tkToplamDigerLimit": "", "tkToplamDigerRisk": "0", "tkToplamGayriNakdiLimit": "0", "tkToplamGayriNakdiRisk": "0", "tkToplamLimit": "0", "tkToplamNakdiLimit": "0", "tkToplamNakdiRisk": "0", "tkToplamRisk": "0" }, "donusDegerleri": { "hataKodu": "0000", "islemSonucu": "0" }, "ersRaporTuru": "D", "raporTur": "FD", "referansNo": "603A796EB0", "varlikTuru": "G" }
I’ll list also my package.json for you seeing my library versions.
{ "requires": true, "lockfileVersion": 1, "dependencies": { "array-filter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/array-filter/-/array-filter-1.0.0.tgz", "integrity": "sha1-uveeYubvTCpMC4MSMtr/7CUfnYM=" }, "available-typed-arrays": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz", "integrity": "sha512-XWX3OX8Onv97LMk/ftVyBibpGwY5a8SmuxZPzeOxqmuEqUCOM9ZE+uIaD1VNJ5QnvU2UQusvmKbuM1FR8QWGfQ==", "requires": { "array-filter": "^1.0.0" } }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", "requires": { "object-keys": "^1.0.12" } }, "es-abstract": { "version": "1.17.6", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz", "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==", "requires": { "es-to-primitive": "^1.2.1", "function-bind": "^1.1.1", "has": "^1.0.3", "has-symbols": "^1.0.1", "is-callable": "^1.2.0", "is-regex": "^1.1.0", "object-inspect": "^1.7.0", "object-keys": "^1.1.1", "object.assign": "^4.1.0", "string.prototype.trimend": "^1.0.1", "string.prototype.trimstart": "^1.0.1" } }, "es-to-primitive": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", "requires": { "is-callable": "^1.1.4", "is-date-object": "^1.0.1", "is-symbol": "^1.0.2" } }, "foreach": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=" }, "fs": { "version": "0.0.1-security", "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", "requires": { "function-bind": "^1.1.1" } }, "has-symbols": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==" }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "is-arguments": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz", "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==" }, "is-callable": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==" }, "is-date-object": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==" }, "is-generator-function": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.7.tgz", "integrity": "sha512-YZc5EwyO4f2kWCax7oegfuSr9mFz1ZvieNYBEjmukLxgXfBUbxAWGVF7GZf0zidYtoBl3WvC07YK0wT76a+Rtw==" }, "is-regex": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", "requires": { "has-symbols": "^1.0.1" } }, "is-symbol": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", "requires": { "has-symbols": "^1.0.1" } }, "is-typed-array": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.3.tgz", "integrity": "sha512-BSYUBOK/HJibQ30wWkWold5txYwMUXQct9YHAQJr8fSwvZoiglcqB0pd7vEN23+Tsi9IUEjztdOSzl4qLVYGTQ==", "requires": { "available-typed-arrays": "^1.0.0", "es-abstract": "^1.17.4", "foreach": "^2.0.5", "has-symbols": "^1.0.1" } }, "object-inspect": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz", "integrity": "sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA==" }, "object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" }, "object.assign": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", "requires": { "define-properties": "^1.1.2", "function-bind": "^1.1.1", "has-symbols": "^1.0.0", "object-keys": "^1.0.11" } }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" }, "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" }, "string.prototype.trimend": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz", "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==", "requires": { "define-properties": "^1.1.3", "es-abstract": "^1.17.5" } }, "string.prototype.trimstart": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz", "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==", "requires": { "define-properties": "^1.1.3", "es-abstract": "^1.17.5" } }, "util": { "version": "0.12.3", "resolved": "https://registry.npmjs.org/util/-/util-0.12.3.tgz", "integrity": "sha512-I8XkoQwE+fPQEhy9v012V+TSdH2kp9ts29i20TaaDUXsg7x/onePbhFJUExBfv/2ay1ZOp/Vsm3nDlmnFGSAog==", "requires": { "inherits": "^2.0.3", "is-arguments": "^1.0.4", "is-generator-function": "^1.0.7", "is-typed-array": "^1.1.3", "safe-buffer": "^5.1.2", "which-typed-array": "^1.1.2" } }, "which-typed-array": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.2.tgz", "integrity": "sha512-KT6okrd1tE6JdZAy3o2VhMoYPh3+J6EMZLyrxBQsZflI1QCZIxMrIYLkosd8Twf+YfknVIHmYQPgJt238p8dnQ==", "requires": { "available-typed-arrays": "^1.0.2", "es-abstract": "^1.17.5", "foreach": "^2.0.5", "function-bind": "^1.1.1", "has-symbols": "^1.0.1", "is-typed-array": "^1.1.3" } }, "xml2js": { "version": "0.4.23", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", "requires": { "sax": ">=0.6.0", "xmlbuilder": "~11.0.0" } }, "xmlbuilder": { "version": "11.0.1", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" } } }
- 521 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in .NET.
You should not care about classes that don’t implement
IDisposable
. Even though their instances are created by the Autofac container, the objects will be automatically GCed as soon as there will be no GC-rooted references to them (e.g. a view is closed and all references to it arenull
-ed). This affects the whole dependency graph – it doesn’t matter how deep it is.If you do have
IDisposable
objects in your setup, the container will of course hold references to them, because it needs to dispose of those objects. However, you still can control how this happens.You can use the
Owned<T>
instances of yourIDisposable
dependencies for that.Consider your example:
class MainVM { private readonly Owned<IMyComponent> _myComponent; public MainVM(Owned<IMyComponent> myComponent) => _myComponent = myComponent; public void DoStuff() => _myComponent.Value.DoStuff(); public void OnViewClosed() => _myComponent.Dispose(); } class MyComponent : IMyComponent, IDisposable { public MyComponent(IOtherComponent otherComponent) { /* ... */ } } class OtherComponent : IOtherComponent, IDisposable { }
Now, when the
OnViewClosed
method gets called, the owned instance ofMyComponent
will be disposed of, including all ofMyComponent
‘s non-shared, disposable dependencies – that isOtherComponent
in our example.Consider reading about the owned instances in the docs.
- 0 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in .NET.
RSA can only be used to encrypt messages whose length is less than the modulus. How much smaller depends on the padding, e.g. 11 bytes in case of PKCS#1 v1.5, s. here. In the case of OAEP, the number of bytes claimed by padding depends on the digest used, s. here. The details are described in RFC8017, RSAES-PKCS1-v1_5 and RSAES-OAEP.
For completeness: RSA without padding (textbook RSA) allows the encryption of messages up to exactly the length of the modulus. In practice, however, padding must always be used for security reasons, so textbook RSA is not a real option.The posted code uses an RSA key of 1024 bits and PKCS#1 v1.5 padding. The maximum size of the message to be encrypted is therefore 117 bytes. Larger messages throw a CryptographicException (Bad Length). That is the reason for your issue.
A 8192 bits (1024 bytes) key would theoretically allow messages up to 1013 bytes in length to be encrypted with PKCS#1 v1.5 Padding. However, the performance decreases strongly with increasing key size, s. here.
Symmetric encryption is more performant than asymmetric encryption. Therefore, in practice larger data volumes are encrypted using symmetric encryption, e.g. AES. However, symmetric encryption has the problem that the communication partners have to exchange the symmetric key. Asymmetric encryption, e.g. RSA, is typically used for this purpose (hybrid encryption), since only the public keys are needed for encryption (which can therefore be exchanged over an insecure channel). However, to prevent a deceptive replacement of the public keys (man in the middel attack), a complex public key infrastructure is generally necessary.
- 461 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
The MySQL query cache is flushed when tables are modified, so it wouldn’t have that effect. It’s impossible to say without seeing the rest of your code, but it’s most likely that your INSERT / DELETE query is failing to run.
- 437 views
- 5 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
$where = "entry_id = ".$entryid; I suppose $entryid should be wrapped in ”
- 400 views
- 2 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
Just another option is to use WITH TIES in concert with a window functions
Example
Select top 1 with ties * From YourTable Order By sum(1) over (partition by FK)
Returns
ID Amount Status FK 1 -1000 T 10 2 -1500 T 11 3 -100 T 12 4 -200 T 13
- 373 views
- 2 answers
- 0 votes
-
Asked on July 16, 2020 in Mysql.
I’m sorry to say this and maybe I’m not solving your problem exactly but PostgreSQL is 10 years older than MySQL and is extremely advanced compared to MySQL and there’s many ways to achieve this easily. Install PostgreSQL and execute this query
CREATE EXTENSION tablefunc;
then voila! And here’s extensive documentation: PostgreSQL: Documentation: 9.1: tablefunc or this query
CREATE EXTENSION hstore;
then again voila! PostgreSQL: Documentation: 9.0: hstore
- 811 views
- 12 answers
- 0 votes
-
Asked on July 16, 2020 in Numpy.
You can split the sorted array to n-1 equal parts and pick the edges. Then find the closest numbers to those edges in your array
def foo(a, n): _a = np.sort(a) ret = np.zeros(n) ret[0], ret[-1] = _a[0], _a[-1] if n==2: return ret midvals = [ret[0]+i*(ret[-1]-ret[0])/(n-1) for i in range(1, n-1)] def closest(arr, val): diff = [abs(v-val) for v in arr] return arr[np.argmin(diff)] for i,v in enumerate(midvals): ret[i+1] = closest(a, v) return ret
- 375 views
- 1 answers
- 0 votes
-
Asked on July 16, 2020 in Python.
You have got two good answers but if you want to run your code with small fixes try this:
import requests from bs4 import BeautifulSoup allcars = [] r = requests.get("https://www.fjordsen.com/en-eu/vehicles/") soup = BeautifulSoup(r.text,"lxml") for items in soup.select(".card-default"): item_title = items.select_one("h4.card-title > a").get_text(strip=True) item_content = [item.text for item in items.select("td")[2:]] cars = ([f'{str(item_title)} {m} {l.split(" ")[0]} ' for m, l in zip(item_content[0::2], item_content[1::2])]) allcars.append(cars) for car in cars: print(car)
output:
Audi A1 75kg Audi A3 75kg Audi A4 90kg Audi A5 90kg Audi A6 100kg Audi A7 100kg Audi A8 100kg Audi Q2 75kg Audi Q3 75kg Audi Q5 75kg...
This code makes two lists allcars and an other cars and loops through cars. allcars contains a list of lists of car manufacturers, mode and load:
[['Audi A1 75kg ', 'Audi A3 75kg ', 'Audi A4 90kg ', 'Audi A5 90kg ', 'Audi A6 100kg ', 'Audi A7 100kg ', 'Audi A8 100kg ', 'Audi Q2 75kg ', 'Audi Q3 75kg ', 'Audi Q5 75kg ', 'Audi Q7 75kg ', 'Audi Q8 100kg '], ['BMW 1 Serie 75kg ', 'BMW 2 Serie Active Tourer 75kg ', 'BMW 2 Serie Cabrio 0kg....
- 418 views
- 3 answers
- 0 votes