私は最初のプログラミング言語を知っています。BS4とPythonを使ったエクササイズを試してみるのに少し問題があります。私はこすりしようとしていますBeautifulsoupとリストを改訂する
あなたは、リストから特定の会社のためのURLを生成したリンクのいずれかをクリックすると次のようになります。 https://www.aisc.org/certification/certified-company?id=3220678
私がしようとしているのは、テーブル形式ではないデータを掻き集めて、企業名を含むexcel csvファイルに変換してから、自分の列(すなわち、アドレス、電話、電子メールなど)。私は会社名と会社情報を分けることができましたが、会社名をリストに追加するのに問題があります。また、会社の情報からタグを解析する際に問題が発生しています。行+ = line.textを使用すると、出力は行= ['a'、 'd'、 'd'、 'r'、 'e'、.......]
ヘルプ私のコードから入力と出力を見つけることができます。
おかげで、
INPUT:
import requests
from bs4 import BeautifulSoup
page = requests.get("https://www.aisc.org/certification/certified-company?id=3220678")
print(page.status_code)
print(page.content)
soup = BeautifulSoup(page.content, 'lxml')
#print(soup.prettify())
#print(soup.find_all('ul', class_='vlist project-details-list'))
#print(soup.find_all('div', class_='unit size1of1'))
for header in soup.find_all('div', class_='unit size1of1'):
for company in header.find_all('h1'):
print(company.text)
for line in soup.find_all('ul', class_='vlist project-details-list'):
row = []
row+= line
print(row)
OUTPUT:
2-K Steel Products, Inc.
['\n', <li><strong>Address:</strong> 65 Murray Circle</li>, '\n', <li><strong>City:</strong> Ashville</li>, '\n', <li><strong>State:</strong> AL</li>, '\n', <li><strong>Zip Code:</strong> 35953</li>, '\n', <li><strong>Country:</strong> United States</li>, '\n', <li><strong>Contact:</strong> Mr. Kal Kimbrough </li>, '\n', <li><strong>Email Address:</strong> <a href="mailto:[email protected]">[email protected]</a></li>, '\n', <li><strong>Phone:</strong> (205) 594-5446</li>, '\n', <li><strong>Website:</strong> <a alt="2-K Steel Products, Inc." href="http://www.2ksteel.com" target="_blank">www.2ksteel.com</a></li>, '\n', <li><strong>Certification/Endorsement Types:</strong> BU</li>, '\n']
ありがとうございました – joe