scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

how to parse value from <b> #210

Open AMJ-7 opened 2 years ago

AMJ-7 commented 2 years ago

how can get value from: Category

<html>
 <head></head>
 <body>
  We are looking for a developer who is experienced in IOS DJI SDK, as well as general drone operating systems.
  <br>
  <br> Your role will be to develop our app based on our android system
  <br>
  <br> We are looking for a detailed person who is and available.
  <br>
  <br> We are looking for long term support:
  <br>
  <br> Please utilise and upload exisiting scope as discussed
  <br>
  <br>
  <b>Hourly Range</b>: $15.00-$19.00 
  <br>
  <b>Posted On</b>: February 16, 2022 04:21 UTC
  <br>
  <b>Category</b>: Mobile App Development
  <br>
  <b>Skills</b>:Virtual Reality, User Authentication, User Profile Creation, iOS, iOS Development, Swift, Smartphone, In-App Purchases, Tablet 
  <br>
  <b>Country</b>: Canada 
  <br>
  <a href="https://www.upwork.com/jobs/IOS-App-Developer-Existing-App_%7E01baae95ea4c434ade?source=rss">click to apply</a> 
 </body>
</html>
MuhammedZakir commented 2 years ago

Why not use either regex or AWK+regex for this?

WIth SwiftSoup: Parse html and use selector syntax [1] using a CSS query like body > b:eq(2) (b:eq(2) because Category is inside third b element). You may use :containsOwn or :matchesOwn pseudo selector rather than :eq if those elements' position will change. After that, call nextElementSibling method on the result you got to get the text after that b element. I haven't tried this, but this should work IIAR.

[1] https://github.com/scinfu/SwiftSoup#use-selector-syntax-to-find-elements.