我想在不同的選項卡我怎樣才能提取IGN網站的URL鏈接
提取的評論的url本網頁 http://uk.ign.com/games/reviews 然後打開前5現在,我已經嘗試不同的選擇去嘗試拿起正確的數據,但沒有東西似乎返回任何東西。我似乎無法超越提取列表中每個評論的網址,更不用說在單獨的標籤中打開前5個。
我使用Python 3與Python IDE
這裏是我的代碼:
import webbrowser, bs4, requests, re
webPage = requests.get("http://uk.ign.com/games/reviews", headers={'User-
Agent': 'Mozilla/5.0'})
webPage.raise_for_status()
webPage = bs4.BeautifulSoup(webPage.text, "html.parser")
#Me trying different selections to try extract the right part of the page
webLinks = webPage.select(".item-title")
webLinks2 = webPage.select("h3")
webLinks3 = webPage.select("div item-title")
print(type(webLinks))
print(type(webLinks2))
print(type(webLinks3))
#I think this is where I've gone wrong. These all returning empty lists.
#What am I doing wrong?
lenLinks = min(5, len(webLinks))
for i in range(lenLinks):
webbrowser.open('http://uk.ign.com/' + webLinks[i].get('href'))
任何運氣找到這些鏈接? – Nevermore
我可以找到網頁上的所有鏈接,但我無法提取我想要的鏈接。 webLinks = webPage.find_all('a') 給我所有頁面上的鏈接 現在我試圖提取「項目標題」與「h3」類下的鏈接。我試過 webItems = webPage.find_all( 'A',{ '階級': 「標題」}) 威比= webPage.find_all(類_ = 「H3」) 沒有這些工作,也許我應該使用一個for循環的某種? – SeyiA