回答編集履歴
3
webdriver.Chrome
answer
CHANGED
@@ -64,8 +64,7 @@
|
|
64
64
|
|
65
65
|
if __name__ == '__main__':
|
66
66
|
# Macの方用のChrome Driverのパスの設定
|
67
|
-
|
67
|
+
driver = webdriver.Chrome()
|
68
|
-
driver = webdriver.Chrome(ChromeDriverManager().install())
|
69
68
|
sleep(1)
|
70
69
|
|
71
70
|
categories = [] # カテゴリーのリンク先
|
2
微修正
answer
CHANGED
@@ -13,8 +13,9 @@
|
|
13
13
|
import csv
|
14
14
|
import datetime
|
15
15
|
|
16
|
+
|
16
17
|
def get_categories():
|
17
|
-
|
18
|
+
category_items = []
|
18
19
|
# Instagramのログインページを指定
|
19
20
|
|
20
21
|
driver.get('https://park.ajinomoto.co.jp/recipe/')
|
@@ -31,25 +32,26 @@
|
|
31
32
|
cat_link = cat_html.find_element_by_xpath('a').get_attribute('href')
|
32
33
|
cat_text = cat_html.find_element_by_xpath('a/span[2]').text
|
33
34
|
|
34
|
-
|
35
|
+
category_items.append({"link": cat_link, "text": cat_text})
|
35
36
|
|
36
37
|
print(cat_link)
|
37
38
|
print(cat_text)
|
38
39
|
|
39
40
|
sleep(1)
|
40
41
|
|
41
|
-
return
|
42
|
+
return category_items
|
42
43
|
|
44
|
+
|
43
45
|
def get_recipe(category, driver):
|
44
46
|
recipe_items = []
|
45
47
|
driver.get(category["link"])
|
46
48
|
sleep(1)
|
47
49
|
|
48
50
|
i = 1
|
49
|
-
|
51
|
+
recipe_page = driver.find_elements_by_xpath('//*[@id="popularityList"]/ul/li')
|
50
52
|
# レシピのリンクを取得
|
51
|
-
for
|
53
|
+
for recipe_html in recipe_page:
|
52
|
-
url =
|
54
|
+
url = recipe_html.find_element_by_xpath(
|
53
55
|
'div[@class="texts"]/div[1]/a').get_attribute('href')
|
54
56
|
|
55
57
|
recipe_items.append({"url": url, "category": category["text"]})
|
@@ -78,4 +80,5 @@
|
|
78
80
|
|
79
81
|
print(recipes)
|
80
82
|
driver.close()
|
83
|
+
|
81
84
|
```
|
1
変数が重複していたので修正
answer
CHANGED
@@ -40,16 +40,15 @@
|
|
40
40
|
|
41
41
|
return categories
|
42
42
|
|
43
|
-
|
44
43
|
def get_recipe(category, driver):
|
45
44
|
recipe_items = []
|
46
45
|
driver.get(category["link"])
|
47
46
|
sleep(1)
|
48
47
|
|
49
48
|
i = 1
|
50
|
-
|
49
|
+
recipe_pages = driver.find_elements_by_xpath('//*[@id="popularityList"]/ul/li')
|
51
50
|
# レシピのリンクを取得
|
52
|
-
for recipe in
|
51
|
+
for recipe in recipe_pages:
|
53
52
|
url = recipe.find_element_by_xpath(
|
54
53
|
'div[@class="texts"]/div[1]/a').get_attribute('href')
|
55
54
|
|