使用Beauty Soup进行Web抓取时Python代码出错
在python代码中,它没有给出预期的输出。未实现初始化“divtitle”的语句。打印“Pass 2”的语句不在预期输出中。还附加了预期输出使用Beauty Soup进行Web抓取时Python代码出错,python,python-3.x,selenium-webdriver,web-scraping,beautifulsoup,Python,Python 3.x,Selenium Webdriver,Web Scraping,Beautifulsoup,在python代码中,它没有给出预期的输出。未实现初始化“divtitle”的语句。打印“Pass 2”的语句不在预期输出中。还附加了预期输出 def scrape(): # after searching the keyword thw page opens, scraping all the headings and content from the search result global driver global ctitle global titles global links
def scrape(): # after searching the keyword thw page opens, scraping all the headings and content from the search result
global driver
global ctitle
global titles
global links
global titles1
ctitle=""
titles=""
links=""
titles1=""
print ( " Getting Searches")
htmlsrc = driver.page_source
bs = BeautifulSoup(htmlsrc,'html.parser')
print(" BS Implemented ")
print(" Inside the try function ")
list1=bs.find('div',attrs={'id':'wgt-list'})
print(" PAss 1 ")
divtitle = list1.find_all('dt' , attrs={'class':'dt mb-4 line'})
print(" Pass 2 ")
for tlink in divtitle:
titles=tlink.find('font').gettext()
print(" Passes the logic, no results returned")
# for a in bs.find_all('a', href=True):
# print ("Found the URL:", a['href'])
print (titles)
print (links)
控制台输出:
Entered the Search Function
Left the Search Function
Getting Searches
BS Implemented
Inside the try function
PAss 1
Pass 2
去掉try…除非你能看到错误。没错,我猜你会因为
*****divtitle=list1
而得到语法错误,这就是,删除那些我做的****@jdigital。“什么也没发生。”奥弗尔萨丹编辑。还是没有结果……什么都没发生是什么意思?您仍然会得到相同的输出,包括无法获得标题
?你犯了什么错误?