I'm going to practice crawling with Python, but I'm asking because the for door doesn't turn around.

Asked 2 years ago, Updated 2 years ago, 84 views

from selenium import webdriver
from bs4 import BeautifulSoup
import sys
import time

driver = webdriver.Chrome("c:/Users/user/Documents/VScode/chromedriver.exe")
driver.implicitly_wait (3)
URL = "http://www.mediseminar.com"
time.sleep(5) 
driver.get (URL)

soup = BeautifulSoup(driver.page_source, "html.parser")
result_monwebi = soup.select_one('#container > section.monWebiWrap > div.monWebi_wrap')

list_no = 0

for i in result_monwebi.find_all('li', attrs={'class':'swiper-slide slick-slide slick-current slick-active'}):
    list_no += 1
    semi_list = i.find('div', attrs={'class':'monWebi_txt'}).text
    print("-----" + str(list_no) + "-----" + semi_list)

driver.close()
sys.exit()

python loops crawling

2022-09-20 11:18

2 Answers

I don't know why, but... I changed it to requests statement and analyzed it again, so it works well. Thank you all for your answers.

from bs4 import BeautifulSoup
import requests
import sys

URL = "http://www.mediseminar.com"
req = requests.get(URL)
#print(req.encoding) - Encoding analysis because Korean is broken

req.encoding='EUC-KR' #Encoding change

soup = BeautifulSoup(req.text, "html.parser")
result_monwebi = soup.select_one('#container > section.monWebiWrap > div.monWebi_wrap')

list_no = 0

for i in result_monwebi.find_all('li', attrs={'class':'swiper-slide'}):
    list_no += 1
    semi_list = i.find('div', attrs={'class':'monWebi_txt'}).text
    print("-----" + str(list_no) + "-----" + semi_list)


sys.exit()


2022-09-20 11:18

If the range of the object subject to the for statement is 0, the for statement does not work.

Compare the following examples.

a = []
for i in a:
    print(1)
a = [6]
for i in a:
    print(1)



2022-09-20 11:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.