selenium爬虫获取免费ip代理
Posted inorilzy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium爬虫获取免费ip代理相关的知识,希望对你有一定的参考价值。
from selenium import webdriver
import pymysql
driver=webdriver.Chrome()
driver.get(‘http://www.xicidaili.com/‘)
ip=driver.find_elements_by_xpath(‘//*[@id="ip_list"]/tbody/tr/td[2]‘)
ip=[i.text for i in ip]
port=driver.find_elements_by_xpath(‘//*[@id="ip_list"]/tbody/tr/td[3]‘)
port=[i.text for i in port]
type=driver.find_elements_by_xpath(‘//*[@id="ip_list"]/tbody/tr/td[6]‘)
type=[i.text for i in type]
conn = pymysql.connect(host = "localhost", port = 3306, user = "root", password = "liuzhiyu", db = "python77", charset = "utf8")
sql=‘insert into ipcontent(ip,port,type) values(%s,%s,%s)‘
cursor = conn.cursor()
for i in range(len(ip)):
print(‘正在插入地{}条‘.format(i))
cursor.execute(sql, (ip[i],port[i],type[i]))
conn.commit()
cursor.close()
conn.close()
以上是关于selenium爬虫获取免费ip代理的主要内容,如果未能解决你的问题,请参考以下文章