|
@@ -16,29 +16,29 @@ import ast
|
|
|
import pymysql
|
|
|
|
|
|
pymysql.install_as_MySQLdb()
|
|
|
-
|
|
|
-import pd
|
|
|
import setting
|
|
|
|
|
|
|
|
|
account = ['chenlinrain','enjoylisteningswift','novak_goodenough']
|
|
|
|
|
|
-account = pd.account
|
|
|
-password = pd.password
|
|
|
+account = 'chenlinrain'
|
|
|
+password = 'weareyoung12'
|
|
|
+
|
|
|
+path = 'C:\\Users\\user\\Downloads\\chromedriver_99\\chromedriver'
|
|
|
|
|
|
-path = '/Users/zooeytsai/Downloads/chromedriver'
|
|
|
-sbaccount = account[2]
|
|
|
-sbpd = password[1]
|
|
|
options = webdriver.ChromeOptions()
|
|
|
-# options.add_argument("--headless") # 視窗背後執行
|
|
|
-options.add_argument("user-agent=%s" % rua())
|
|
|
+options.add_argument("--headless") # 視窗背後執行
|
|
|
+options.add_argument("user-agent=%s" % setting.rua())
|
|
|
+print(setting.rua())
|
|
|
|
|
|
|
|
|
def download_post():
|
|
|
- hashtag = '寵物蛋糕'
|
|
|
+ sbaccount = 'chenlinrain'
|
|
|
+ sbpd = password
|
|
|
+ hashtag = '實體課'
|
|
|
url = f"https://www.instagram.com/explore/tags/{hashtag}/"
|
|
|
s = Service(path)
|
|
|
- driver = webdriver.Chrome(service=s, options=options)
|
|
|
+ driver = webdriver.Chrome(executable_path=path, options=options)
|
|
|
driver.implicitly_wait(3)
|
|
|
driver.get('https://www.instagram.com/')
|
|
|
time.sleep(5)
|
|
@@ -52,7 +52,7 @@ def download_post():
|
|
|
driver.get(url)
|
|
|
time.sleep(3)
|
|
|
limit_of_posts = 10
|
|
|
- limit_of_scroll = 100
|
|
|
+ limit_of_scroll = 40
|
|
|
c = 0
|
|
|
c_sroll = 0
|
|
|
link = []
|
|
@@ -84,14 +84,17 @@ def download_post():
|
|
|
|
|
|
|
|
|
def hashtag():
|
|
|
- input_hashtag = 'pet_cake'
|
|
|
+ sbaccount = 'novak_goodenough'
|
|
|
+ sbpd = password
|
|
|
+ input_hashtag = 'face_to_face'
|
|
|
collect_hashtag = []
|
|
|
c = 0
|
|
|
+ rest = 0
|
|
|
f = open('link.txt', 'r')
|
|
|
result = f.read()
|
|
|
link = ast.literal_eval(result)
|
|
|
s = Service(path)
|
|
|
- driver = webdriver.Chrome(service=s, options=options)
|
|
|
+ driver = webdriver.Chrome(executable_path=path, options=options)
|
|
|
driver.implicitly_wait(3)
|
|
|
driver.get('https://www.instagram.com/')
|
|
|
time.sleep(5)
|
|
@@ -105,7 +108,8 @@ def hashtag():
|
|
|
driver.find_element(By.XPATH, '//*[@id="react-root"]/section/main/div/div/div/section/div/button').click()
|
|
|
time.sleep(3)
|
|
|
|
|
|
- for url in link:
|
|
|
+ for i,url in enumerate(link):
|
|
|
+ print(i)
|
|
|
driver.get(f"https://www.instagram.com/{url}")
|
|
|
soup = BeautifulSoup(driver.page_source, 'html.parser')
|
|
|
hashtags = soup.find_all('a', class_='xil3i')
|
|
@@ -113,33 +117,42 @@ def hashtag():
|
|
|
print(tag.text)
|
|
|
collect_hashtag.append(tag.text)
|
|
|
c += 1
|
|
|
+ rest+=1
|
|
|
if c > 10:
|
|
|
time.sleep(randint(5, 10))
|
|
|
c = 0
|
|
|
+ if rest>100:
|
|
|
+ time.sleep(randint(60,90))
|
|
|
+ rest=0
|
|
|
driver.close()
|
|
|
print(collect_hashtag)
|
|
|
+
|
|
|
db_company = pymysql.connect(host='db.ptt.cx',
|
|
|
user='choozmo',
|
|
|
password='pAssw0rd',
|
|
|
database='seo')
|
|
|
+ print('開始開始寫進db')
|
|
|
cur = db_company.cursor()
|
|
|
- query_new_col = f"ALTER TABLE seo.ig_pet ADD COLUMN {input_hashtag} VARCHAR(45) NULL"
|
|
|
+ query_new_col = f"ALTER TABLE seo.ig_pet_2 ADD COLUMN {input_hashtag} VARCHAR(45) NULL"
|
|
|
cur.execute(query_new_col)
|
|
|
id_number = 0
|
|
|
- cur.execute("select * from seo.ig_pet order by `index` desc limit 1")
|
|
|
+ cur.execute("select * from seo.ig_pet_2 order by `id` desc limit 1")
|
|
|
last_id = cur.fetchall()[0][0]
|
|
|
insert_row = len(collect_hashtag) - last_id
|
|
|
for i in range(0, insert_row):
|
|
|
- query_insert = f"INSERT INTO seo.ig_pet ({input_hashtag}) VALUES ('')"
|
|
|
+ query_insert = f"INSERT INTO seo.ig_pet_2 ({input_hashtag}) VALUES ('')"
|
|
|
cur.execute(query_insert)
|
|
|
+ db_company.commit()
|
|
|
+ print(i)
|
|
|
for i in collect_hashtag:
|
|
|
i = i.replace('#', '')
|
|
|
- query_update = f"UPDATE seo.ig_pet SET {input_hashtag}='{i}' where `index`='{id_number}'"
|
|
|
+ query_update = f"UPDATE seo.ig_pet_2 SET {input_hashtag}='{i}' where `id`='{id_number}'"
|
|
|
cur.execute(query_update)
|
|
|
id_number += 1
|
|
|
-
|
|
|
- db_company.commit()
|
|
|
+ db_company.commit()
|
|
|
+ print(i,id_number)
|
|
|
db_company.close()
|
|
|
+ print(len(link))
|
|
|
return hashtag
|
|
|
|
|
|
|