开发者

Manipulate website dropdown menu in Python

开发者 https://www.devze.com 2023-02-12 17:27 出处:网络
I\'ve been searching the web for an answer to the following question, and my lack of success might have to do with my inexperience in web programming/html. If so and there\'s an obvious answer, sorry

I've been searching the web for an answer to the following question, and my lack of success might have to do with my inexperience in web programming/html. If so and there's an obvious answer, sorry for bugging you all. I've been trying to parse a bunch of text from a website, and I found the python script html2text.py, which does a nice job of presenting the website in a way that I can parse. However, in order to get to all the information, I need to access a drop down menu on the site. The drop down menu controls which year of data is displayed, and I want to get all available years. I've seen that with urllib2 I can access a website, and it looks like I can send information to a website that way too, but I haven't been able to figure out exactly how to manipulate the drop down menus. The website 开发者_运维百科I'm interested in is http://www.nfldata.com/nfl-stats/team-stats.aspx if that helps at all. Thanks in advance for any advice you can provide.

-Matt


Check out the xml libraries within python. You can take the raw html text and parse it into a Document Object Model (DOM) interface:

http://docs.python.org/library/xml.dom.minidom.html


What you are looking at is not a Drop Down menu, but a Select widget.

You should be able to parse this, and find all of the <option value="X">name<option> entries. The X is what you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消