문제 설명
크롤링 출력 ‑ 두 변수 연결 (Crawling output ‑ connecting two variables)
약간의 실수가 있었기 때문에 내 코드를 수정했습니다. 제안된 대로 dic을 생성했지만 이제 if...else
문</p>을 매번 사용하지 않고 완료하는 방법에 대한 단서를 얻었습니다.
참조 솔루션
방법 1:
I modified your code above to get it working. Here is an example of how you would use the dictionary
to get PartnerID
.
RegionIDArray = [7236, 7665]
dict = {7236: 2, 7665: 3} #{'Rome': 3, 'Paris': 2}
for RegionID in RegionIDArray:
for page in range(1,2):
url = "http://www.isango.de/affiliatesearch.aspx?®ionid=" + str(RegionID) + "&pid=" + str(page)
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html)
g_data = soup.find_all("div", {"class": "gridHeadOuter productInfoOuter"})
for item in g_data:
Header = item.find_all("div", {"class": "offerInto"})
Header_final = (Header[0].contents[0].text.strip())
print("Header: " + Header_final + " | " + "PartnerID: " + str(dict[RegionID]))
The output is:
Header: Washington Odyssey Lunch Cruise | PartnerID: 2
Header: Audio Tour, Candlelit Dinner and Concert at Charlottenburg Palace, Berlin | PartnerID: 3
(by Serious Ruffy、dstudeba)