Chromeのログイン情報を保持しながらスクレイピングする

Seleniumを使用して開いたChromeのログイン情報を残す。
これで一回ログインした情報を残す。

from selenium import webdriver

# 新しいChromeプロファイルを作成
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:/Users/YourUsername/AppData/Local/Google/Chrome/User Data/ProfileName")
driver = webdriver.Chrome(options=options)

これにより、前回のセッションからログイン情報を引き継ぐことができます。

BeautifulSoupでソースから特定のリンクだけ抽出してみた。

#find_all('[タグ]', class_="[クラス名]")でaタグ全体を抽出
for element in soup.find_all('a', class_="link"):
    #get関数の引数に「属性」を入れて内部を抜き出す。
    url = element.get('href')

実際うまくいったコード

import requests
from bs4 import BeautifulSoup

url = 'リンク先'

html = requests.get(url)

soup = BeautifulSoup(html.content, 'html.parser')

for element in soup.find_all('a', class_="link"):
    url = element.get('href')
    print(url)

ShopifyにオリジナルCSSを使用する

コードで編集をしてから

1.Assetsフォルダ直下に「 original.css」なる独自のcssを作成する
2.Layoutフォルダにある「theme.liquid 」でcssを読み込む
3.あとは好きなようにいつも通り作成する。


個人的には下手なASPを使うくらいなら、Shopifyのほうが自由度も高いし、
お客さんの側で更新できるパーツも残したりできるので、
こっちの方が作業しやすいかもしれないな。

Shopifyの商品詳細で値を取得する

■タイトルを取得する

{{ product.title }}


■説明を取得する

{{ product.description }}

■価格を取得する(ここは「product-price.liquid」を呼び出しているだけ。)

{% include 'product-price', variant: current_variant, show_vendor: section.settings.show_vendor %}


個人的には楽天の「PC商品説明文」のように縦長のスタイルにしたいので、
以下のコードを

<div class="product-single__description rte">
  {{ product.description }}
</div>

以下のDIVタグから出してあげて

<div class="product-template__container page-width"
  id="ProductSection-{{ section.id }}"
  data-section-id="{{ section.id }}"
  data-section-type="product"
  data-enable-history-state="true"
  data-ajax-enabled="{{ settings.enable_ajax }}"
>

最後にCSSを当ててあげると完璧です。
これShopifyカスタマイズできたら、結構自由度高くなりますな。