0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BeautifulSoupでHTMLからForm,Link情報を取得

Posted at
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://xxxxx.co.jp")
bsObj = BeautifulSoup(html.read())

# Fromの情報を取得
for form_tag in bsObj.body.findAll("form"):

    print("SEND URL : {action}".format(action = form_tag.attrs.get("action",None)))
    print("METHOD   : {method}".format(method = form_tag.attrs.get("method",None)))
    print("ENCTYPE  : {enctype}".format(enctype = form_tag.attrs.get("enctype",None)))

    for input_tag in form_tag.findAll("input"):

        print("INPUT NAME : {name}".format(name = input_tag.attrs.get("name",None)))
        print("INPUT VALUE : {value}".format(value = input_tag.attrs.get("value",None)))
        print("INPUT TYPE : {type}".format(type = input_tag.attrs.get("type",None)))

    for text_tag in form_tag.findAll("text"):

        print("TEXT NAME : {name}".format(name = text_tag.attrs.get("name",None)))
        print("TEXT VALUE : {value}".format(value = text_tag.get_text()))


# Aタグの情報を取得
for a_tag in bsObj.body.findAll("a"):

    print("SEND URL : {url}".format(url = a_tag.attrs.get("href",None)))
    
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?