我有一个名为IP2.txt的文件,该文件包含2行,如下所示。
103.201.150.209
113.170.129.113
import requests
from bs4 import BeautifulSoup
import re
fh = open('IP2.txt')
for line in fh:
ip = line.rstrip()
print(ip)
loads = {'q':line.rstrip(),'engine':1}
r = requests.get('https://fortiguard.com/search',params=loads)
# print(r.url)
# print(r.text)
Link_text = r.text
soup = BeautifulSoup(Link_text, 'lxml')
for product in soup.find_all('section', class_='iprep'):
product_title = product.find("a").text
print(ip+':'+ product_title)
fh.close()
上面代码的输出是这样的。
103.201.150.209
113.170.129.113
113.170.129.113:Malicious Websites
您可以看到其阅读的最后一行,并跳过第一个值:103.201.150.209
请对此提供帮助非常感谢