0
我在“op.gg”网站上使用正则表达式抓取游戏玩家的名称。Python网络抓取和正则表达式
我用reqexr.com网站来检查我想要得到的东西的正则表达式,我找到了200名玩家。
但我的python代码不起作用。我打算将200个数据插入列表中。但列表是空的。
我认为单引号(')不适用于我的Python代码。
这里是我的一块代码..
import requests
from bs4 import BeautifulSoup
import re
user_name = input()
def hex_user_name(user_name):
hex_user_name = [hex(x) for x in user_name.encode('utf-8')]
for i,j in enumerate(hex_user_name):
hex_user_name[i] = '%'+j[2:].upper()
return ''.join(hex_user_name)
def get_user_name(user_name):
q = re.compile('k\'>([^<]{1,16})', re.M)
site = 'http://www.op.gg/summoner/userName=' + user_name
source_code = requests.get(site)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, 'lxml')
name = soup.find_all('a')
listB = q.findall(re.sub('[\s\n,]*', '' ,str(name)))
print(listB)
get_user_name(hex_user_name(user_name))
我强烈怀疑这行
q = re.compile('k\'>([^<]{1,16})', re.M)
有问题..但我找不到任何错误。
这是我想对正则表达式中使用的:k\'>([^<]*)
而且이곳은지옥인가(韩字)是我想要得到的HTML代码中的数据。
<div class="SummonerName">
<a href="//www.op.gg/summoner/userName=%EC%9D%B4%EA%B3%B3%EC%9D%80%EC%A7%80%EC%98%A5%EC%9D%B8%EA%B0%80" class="Link" target='_blank'>이곳은지옥인가</a>
</div>
我真的很感谢你们帮我了..