[Solved] Python how to: convert set to int [closed]

I’m not sure what you’re trying to accomplish with this code: for word in lst: oldset.add(word) oldset = len(oldset) But what you are actually accomplishing is as follows: you loop through all the words in lst, and for each word, you try to add the word to oldset, and then you demolish oldset and replace … Read more

[Solved] How to extract URL from HTML anchor element using Python3? [closed]

You can use built-in xml.etree.ElementTree instead: >>> import xml.etree.ElementTree as ET >>> url=”<a rel=”nofollow” href=”https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip”>XYZ</a>” >>> ET.fromstring(url).attrib.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” This works on this particular example, but xml.etree.ElementTree is not an HTML parser. Consider using BeautifulSoup: >>> from bs4 import BeautifulSoup >>> BeautifulSoup(url).a.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” Or, lxml.html: >>> import lxml.html >>> lxml.html.fromstring(url).attrib.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” Personally, I prefer BeautifulSoup – … Read more