Pythonウェブスクレーピング
25913 ワード
プロイセンペソソコムは、プロイセンデApplitoデApplitoデAppleto e Nextjsなしフロントエンド、foi quando me deparee com o seguinte問題、EUテリアque exibir aproximadamente 18 dadosデ118人のエメメントスda tabela periは、dia、コレットSes Dados Seria Humanamente Invi -ルヴェル、フォイアッシズムque a ideia de criar esseスクリプトです.
として、Informaは、Des Elemementos Ser o o Extra - Re Das DoサイトPubChen、como OS dadosエストo - dentroデ馬ポップアップ、Informzareoセレンパラabrir o Navegador e ExtrairとしてInforma Sys
chormedriver
IntelotecaウェブドライバーE Colorque O CaminhoデInstala Some
パラABRIR O Navegadorは、Necessに乗ります.入手してください、パラExtrair Os Dados DA P .
パラExtrairのOS dados da pのdapのginaのエヌes rio inspecionarのos elementos da pのdegge e pegar osの識別子を使用しなさい.
コモエサパルティヤーラは、2つの楽しみがそうであることを意味します.
パラグラビアのOS dadosなしArquivo JSONのEllessは、リオモンタールo objeto que serは、enviado para o arquivoを引きます.
アゴラque o oのスクリプトjのエッセイは、Fescionandoは、プリフォーマファーザーElar Chamar Automaticteトダ語の118のポップアップを、serを使用します.
コマンド
結果
リポジトリ
Tabela períodica 👩🏿💻
ドライバの設定
として、Informaは、Des Elemementos Ser o o Extra - Re Das DoサイトPubChen、como OS dadosエストo - dentroデ馬ポップアップ、Informzareoセレンパラabrir o Navegador e ExtrairとしてInforma Sys
chormedriver
IntelotecaウェブドライバーE Colorque O CaminhoデInstala Some
pip install webdriver
from selenium import webdriver
driver = webdriver.Chrome( executable_path='C:/Users/{user}/Downloads/chromedriver_win32/chromedriver.exe')
コンフィギュレーションラテンダP P
パラABRIR O Navegadorは、Necessに乗ります.入手してください、パラExtrair Os Dados DA P .
pip install beautifulsoup4
from bs4 import BeautifulSoup
url = "https://pubchem.ncbi.nlm.nih.gov/periodic-table/#popup=1"
driver.get(url)
content = driver.page_source
soup = BeautifulSoup(content)
ペガド・オス・ダドス
パラExtrairのOS dados da pのdapのginaのエヌes rio inspecionarのos elementos da pのdegge e pegar osの識別子を使用しなさい.
コモエサパルティヤーラは、2つの楽しみがそうであることを意味します.
def find_span(data_label, symbol):
formatted_string = data_label.format(symbol)
href = soup.find(
"a", {"data-label": formated_string})
if href:
span = href.find("span", {"class": "capitalized"})
if span:
return span.text
else:
return "N/A"
else:
return "N/A"
def find_div(class_name):
div = soup.find(
"div", {"class": class_name})
if div:
return div.text
else:
return "N/A"
symbol = find_div("f-3")
name = find_div("f-125 f-lh-15")
type_element = find_div("f-0875 capitalized f-lh-15")
standard_state = find_span(
'Content Link (List View): {}; Standard State Property Value', symbol)
atomic_mass = find_span(
"Content Link (List View): {}; Atomic Mass Property Value", symbol)
electron_configuration = find_span(
"Content Link (List View): {}; Electron Configuration Property Value", symbol)
oxidation_states = find_span(
"Content Link (List View): {}; Oxidation States Property Value", symbol)
electronegativity = find_span(
"Content Link (List View): {}; Electronegativity (Pauling Scale) Property Value", symbol)
atomic_radius = find_span(
"Content Link (List View): {}; Atomic Radius (van der Waals) Property Value", symbol)
ionization_energy = find_span(
"Content Link (List View): {}; Ionization Energy Property Value", symbol)
electron_affinity = find_span(
"Content Link (List View): {}; Electron Affinity Property Value", symbol)
melting_point = find_span(
"Content Link (List View): {}; Melting Point Property Value", symbol)
boiling_point = find_span(
"Content Link (List View): {}; Boiling Point Property Value", symbol)
density = find_span(
"Content Link (List View): {}; Density Property Value", symbol)
year_discovered = find_span(
"Content Link (List View): {}; Year Discovered Property Value", symbol)
グラドダスダドノノArquivo
パラグラビアのOS dadosなしArquivo JSONのEllessは、リオモンタールo objeto que serは、enviado para o arquivoを引きます.
data = {"id": id, "symbol": symbol,
"name": name,
"type": type_element,
"standardState": standard_state,
"atomicMass": atomic_mass,
"electronConfiguration": electron_configuration,
"oxidationStates": oxidation_states,
"electronegativity": electronegativity,
"atomicRadius": atomic_radius,
"ionizationEnergy": ionization_energy,
"electronAffinity": electron_affinity,
"meltingPoint": melting_point,
"boilingPoint": boiling_point,
"density": density,
"yearDiscovered": year_discovered}
デポ・イェーヌ・O・レヴェルdriver.close()
参考文献Lito Pozso ' Instalar A BityNoteca JSONパラque ela salve os dados pip install json
Journal . comは、Blogoteteca Instalada、アゴラの詩のパスo o JSON形式のFormulawith open('data.json', 'w') as f:
json.dump(data, f)
<研究ノート>オス・エメメントスの作品
アゴラque o oのスクリプトjのエッセイは、Fescionandoは、プリフォーマファーザーElar Chamar Automaticteトダ語の118のポップアップを、serを使用します.
import json
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome(
executable_path='C:/Users/{user}/Downloads/chromedriver_win32/chromedriver.exe')
array_elements = []
id = 1
while (id <= 118):
url = "https://pubchem.ncbi.nlm.nih.gov/periodic-table/#popup={}".format(
id)
driver.get(url)
content = driver.page_source
soup = BeautifulSoup(content)
def find_span(data_label, symbol):
formated_string = data_label.format(symbol)
href = soup.find(
"a", {"data-label": formated_string})
if href:
span = href.find("span", {"class": "capitalized"})
if span:
return span.text
else:
return "N/A"
else:
return "N/A"
def find_div(class_name):
div = soup.find(
"div", {"class": class_name})
if div:
return div.text
else:
return "N/A"
symbol = find_div("f-3")
name = find_div("f-125 f-lh-15")
type_element = find_div("f-0875 capitalized f-lh-15")
standard_state = find_span(
'Content Link (List View): {}; Standard State Property Value', symbol)
atomic_mass = find_span(
"Content Link (List View): {}; Atomic Mass Property Value", symbol)
electron_configuration = find_span(
"Content Link (List View): {}; Electron Configuration Property Value", symbol)
oxidation_states = find_span(
"Content Link (List View): {}; Oxidation States Property Value", symbol)
electronegativity = find_span(
"Content Link (List View): {}; Electronegativity (Pauling Scale) Property Value", symbol)
atomic_radius = find_span(
"Content Link (List View): {}; Atomic Radius (van der Waals) Property Value", symbol)
ionization_energy = find_span(
"Content Link (List View): {}; Ionization Energy Property Value", symbol)
electron_affinity = find_span(
"Content Link (List View): {}; Electron Affinity Property Value", symbol)
melting_point = find_span(
"Content Link (List View): {}; Melting Point Property Value", symbol)
boiling_point = find_span(
"Content Link (List View): {}; Boiling Point Property Value", symbol)
density = find_span(
"Content Link (List View): {}; Density Property Value", symbol)
year_discovered = find_span(
"Content Link (List View): {}; Year Discovered Property Value", symbol)
data = {"id": id, "symbol": symbol,
"name": name,
"type": type_element,
"standardState": standard_state,
"atomicMass": atomic_mass,
"electronConfiguration": electron_configuration,
"oxidationStates": oxidation_states,
"electronegativity": electronegativity,
"atomicRadius": atomic_radius,
"ionizationEnergy": ionization_energy,
"electronAffinity": electron_affinity,
"meltingPoint": melting_point,
"boilingPoint": boiling_point,
"density": density,
"yearDiscovered": year_discovered}
array_elements.append(data)
id = id + 1
driver.close()
with open('data.json', 'w') as f:
json.dump(array_elements, f)
rodandoスクリプト
コマンド
python script.py
ディスコグラフィー結果
リポジトリ
Tabela períodica 👩🏿💻
Reference
この問題について(Pythonウェブスクレーピング), 我々は、より多くの情報をここで見つけました https://dev.to/marinasantana/python-web-scraping-escrever-em-arquivo-json-5329テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol