TheGateKeeper
TheGateKeeper

Reputation: 4530

Taking all the values from a dropDownList

If a website has a dropDownList, is it possible to extract all the values along with their ID using c#?

Thanks

As in:

<select name='dropDownList'  >
<option value='0'>Watever</option>
<option value="1">Watever</option>
<option value="2">Watever</option>
<option value="3">Watever</option>
<option value="4">Watever</option>

I want to extract all the "value" as well as their corresponsing text.

Upvotes: 0

Views: 356

Answers (2)

Ali Adravi
Ali Adravi

Reputation: 22763

I have already scrapped many sites, but there is no hard and fast rule for it.

I always use my own logic and easiest way is the sub string.

  1. Take entire page HTML as a string
  2. use substring to get all the option
  3. split the option to do the for loop
  4. do the for loop
  5. in every loop subtract you value and text

I am not saying that there is no better way but hardly you will get any.

Hope it will help you

Upvotes: 1

jwillmer
jwillmer

Reputation: 3789

If you use a ASP.NET site and add the dropdown list as element you can easily get/set the properties. If it´s not your site and you use a client to get to the html code you have to parse it. For html the HtmlAgilityPack is the best solution but you can also try to use regex if the query isn´t to complex.

Upvotes: 1

Related Questions