Python爬虫期末试题(编程题答案)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python爬虫期末试题(编程题答案)相关的知识,希望对你有一定的参考价值。
参考技术A from seleniumimport webdriverimport time
from selenium.webdriverimport ActionChains
driver = webdriver.Chrome()
driver.get("https://accounts.douban.com/passport/login")
# 点击密码登录
driver.find_element_by_class_name('account-tab-account').click()
# 定位账户 # 输入内容
driver.find_element_by_id('username').send_keys('2331566038')
driver.find_element_by_id('password').send_keys('*********')
# 点击登录
driver.find_element_by_link_text('登录豆瓣').click()
# 进入内嵌滑动验证页面
iframe = driver.find_element_by_id('tcaptcha_iframe')
driver.switch_to_frame(iframe)
element = driver.find_element_by_xpath('//*[@id="tcaptcha_drag_thumb"]')
ActionChains(driver).click_and_hold(on_element=element).perform()
ActionChains(driver).move_to_element_with_offset(to_element=element,xoffset=180,yoffset=0).perform()
driver.save_screenshot('豆瓣.png')
time.sleep(5)
driver.quit()
import urllib.request
import urllib.parse
url ="http://www.baidu.com/s"
word = "wd":"浙江大学"
word = urllib.parse.urlencode(word)
new_url = url +"?" + word
header =
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
resquest = urllib.request.Request(new_url,headers = header,)
response = urllib.request.urlopen(resquest)
html = response.read().decode('utf-8')
print(html)
以上是关于Python爬虫期末试题(编程题答案)的主要内容,如果未能解决你的问题,请参考以下文章