![]() |
|
[Python] Beautiful Soup finding href - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Beautiful Soup finding href (/showthread.php?tid=5370621) |
Beautiful Soup finding href - IGotTheKeys - Aug 10, 2016 Hey, im trying to retrieve the 64 from this <a> tag.Could anyone tell me how to use the soup.find function in regards to finding a href and a class(in this case the "temp" class ) "<a href="THELINKWOULDGOHEREBUTICANTPOSTIT">London, United Kingdom<span class="temp">64°</span><span class="icon i-33-s"></span></a> " Heres what ive tried: data1 = [link['href'] for link in soup.findAll("a", {"class": "temp"})] data1= soup.find('a', attrs={'class' : 'temp'}).find('a', href=True) * - zmetra - Aug 10, 2016 (Aug 10, 2016 04:22 PM)IGotTheKeys Wrote: Hey, im trying to retrieve the 64 from this <a> tag.Could anyone tell me how to use the soup.find function in regards to finding a href and a class(in this case the "temp" class ) I'm not familiar with beautifulsoup, but you can use the re module. Code # Removing the ''.join will output a tuple.Output: Quote:THELINKWOULDGOHEREBUTICANTPOSTIT * - Madathf - Aug 13, 2016 PHP Code 🤝 * - SIM-1866423 - Aug 13, 2016 PHP Code Py3 not use findAll anymore be careful(https://www.crummy.com/software/BeautifulSoup/bs4/doc/). * - Goodies - Aug 13, 2016 (Aug 10, 2016 05:19 PM)zmetra Wrote: I'm not familiar with beautifulsoup, but you can use the re module. I love regex as much as the next guy, assuming the next guy also has nightmares about regex, but bs4 is the way to go for any html parsing project. |