#URLリストを読み込みスクレイピングしたい
いつもお世話になっております!
下記のコードでスクレイピングしたいのですがデータが出力されません。
別のサイトのデータをとってきたときはいけたのですが…
リストも読込みますし、エラーも出ないため解決方法がわからず質問させて頂きました。
宜しくお願い致します。
python
1from bs4 import BeautifulSoup 2 3with open('sd.txt') as f: 4 for line in f.readlines(): 5 target_url = line.strip() 6 print(target_url) 7 8 9 html = urllib.request.urlopen(target_url).read() 10 soup = BeautifulSoup(html, 'lxml') 11 12 title = soup.findAll('span' , class_='product-name') 13 imgage = soup.findAll('div' , id_='thumbnail_0') 14 15 for f in imgage: 16 for link in f.findAll('img'): 17 imgoutput = link.attrs['src'] 18 19 with open('sd_img.csv','a', encoding='cp932' ,newline='') as f: 20 writer = csv.writer(f) 21 writer.writerow([title , imgoutput]) 22
text
1https://www.superdelivery.com/p/r/pd_p/4444756/ 2https://www.superdelivery.com/p/r/pd_p/4992513/ 3https://www.superdelivery.com/p/r/pd_p/4374220/ 4https://www.superdelivery.com/p/r/pd_p/5781450/ 5https://www.superdelivery.com/p/r/pd_p/5781475/
回答3件
あなたの回答
tips
プレビュー