CSVファイルに保存されているURLのリストを削り取る必要があります。Beautiful Soup&Pythonを使用してCSVから複数のURLを削る
https://stackoverflow.com;code site;
https://steemit.com;block chain social site;
は、次のコードは動作します:
私のようなあなたのurls.csv
ファイルが見えると仮定すると、美しいスープ
CSVファイルに保存されているURLのリストを削り取る必要があります。Beautiful Soup&Pythonを使用してCSVから複数のURLを削る
https://stackoverflow.com;code site;
https://steemit.com;block chain social site;
は、次のコードは動作します:
私のようなあなたのurls.csv
ファイルが見えると仮定すると、美しいスープ
に非常に新しいです
#!/usr/bin/python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup #required to parse html
import requests #required to make request
#read file
with open('urls.csv','r') as f:
csv_raw_cont=f.read()
#split by line
split_csv=csv_raw_cont.split('\n')
#remove empty line
split_csv.remove('')
#specify separator
separator=";"
#iterate over each line
for each in split_csv:
#specify the row index
url_row_index=0 #in our csv example file the url is the first row so we set 0
#get the url
url = each.split(separator)[url_row_index]
#fetch content from server
html=requests.get(url).content
#soup fetched content
soup= BeautifulSoup(html)
#show title from soup
print soup.title.string
結果:
Stack Overflow - Where Developers Learn, Share, & Build Careers
Steemit
その他の情報:beautifulsoupおよびrequests
お試しください:) – yash
*あなたのコード*の正確な解決策は見つかりません。しかし、CSVを読み、HTTPリクエストを作成し、PythonでHTMLを解析するための多くのドキュメントがあります。あなたのコードが動作する特定の方法ではなく、それに焦点を当ててください。 –
あなたが何かを検索したと言いたいのであれば、何が動作していないかを示してください。その結果、可能な限り重複しないように質問します。 –