Related
I have a problem when I'm defining the code in (Python with Selenium)to enter the password on a virtual keyboard where the numbers change position every time the page is updated. I have no problem matching the letters because they are static. But I can't find how to click on the correct numbers.
Note: The password field only allows you to enter values through the keyboard.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time
driver = webdriver.Chrome(
'C:/Users/migxx/Documents/Mixx/Python/IB_TaskBot/chromedriver.exe')
driver.get('https://bancaporinternet.interbank.pe/')
# target username
cardNumber = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[id='25']")))
documentNumber = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[id='39']")))
cardNumber.clear()
cardNumber.send_keys("4211550014142020")
documentNumber.clear()
documentNumber.send_keys("10100010")
act = ActionChains(driver)
act.send_keys(Keys.TAB).perform()
#In this part I cannot enter the password!!!!!!!!!!!!!
This ins the first preview
Here is the numpad with the code
The Easiest solution I can think of is as follows:
Click on the field to display the keyboard
driver.find_element_by_xpath('//*[#id="46"]').click()
Since each digit is predefined and it will be present in either of the following locations depending on the digit:
a->span->svg->g->path[d='...'] (OR)
a->span->svg->g->polygon[points='...']
What you can do is to define your own digits like this:
zero_d = "M31.15625,35.296875 C31.15625,38.6823086 30.5781308,41.1979084 29.421875,42.84375 C28.2656192,44.4895916 26.4583456,45.3125 24,45.3125 C21.5729045,45.3125 19.7760475,44.5078205 18.609375,42.8984375 C17.4427025,41.2890545 16.8385419,38.8854327 16.796875,35.6875 L16.796875,31.828125 C16.796875,28.4843583 17.3749942,26.0000081 18.53125,24.375 C19.6875058,22.7499919 21.4999877,21.9375 23.96875,21.9375 C26.4166789,21.9375 28.2187442,22.7213463 29.375,24.2890625 C30.5312558,25.8567787 31.1249998,28.2760253 31.15625,31.546875 L31.15625,35.296875 Z M28.265625,31.34375 C28.265625,28.8958211 27.9218784,27.1119848 27.234375,25.9921875 C26.5468716,24.8723902 25.4583408,24.3125 23.96875,24.3125 C22.4895759,24.3125 21.4114617,24.8697861 20.734375,25.984375 C20.0572883,27.0989639 19.7083334,28.8124884 19.6875,31.125 L19.6875,35.75 C19.6875,38.2083456 20.0442673,40.0234316 20.7578125,41.1953125 C21.4713577,42.3671934 22.5520761,42.953125 24,42.953125 C25.4270905,42.953125 26.4869757,42.4010472 27.1796875,41.296875 C27.8723993,40.1927028 28.2343748,38.4531369 28.265625,36.078125 L28.265625,31.34375 Z"
one_points = "27.390625 44 24.484375 44 24.484375 24.734375 18.65625 26.875 18.65625 24.25 26.9375 21.140625 27.390625 21.140625"
two_d = "M31.796875,45 L16.890625,45 L16.890625,42.921875 L24.765625,34.171875 C25.9322975,32.8489517 26.736977,31.7734416 27.1796875,30.9453125 C27.622398,30.1171834 27.84375,29.2604211 27.84375,28.375 C27.84375,27.1874941 27.4843786,26.2135455 26.765625,25.453125 C26.0468714,24.6927045 25.0885477,24.3125 23.890625,24.3125 C22.4531178,24.3125 21.3359415,24.7213501 20.5390625,25.5390625 C19.7421835,26.3567749 19.34375,27.4947844 19.34375,28.953125 L16.453125,28.953125 C16.453125,26.8593645 17.1275974,25.1666731 18.4765625,23.875 C19.8255276,22.5833269 21.630197,21.9375 23.890625,21.9375 C26.0052189,21.9375 27.6770772,22.492182 28.90625,23.6015625 C30.1354228,24.710943 30.75,26.1874908 30.75,28.03125 C30.75,30.2708445 29.3229309,32.9374845 26.46875,36.03125 L20.375,42.640625 L31.796875,42.640625 L31.796875,45 Z"
three_d = "M21.09375,32.21875 L23.265625,32.21875 C24.6302152,32.1979166 25.7031211,31.8385452 26.484375,31.140625 C27.2656289,30.4427048 27.65625,29.5000059 27.65625,28.3125 C27.65625,25.64582 26.3281383,24.3125 23.671875,24.3125 C22.4218688,24.3125 21.4244829,24.6692673 20.6796875,25.3828125 C19.9348921,26.0963577 19.5625,27.0416608 19.5625,28.21875 L16.671875,28.21875 C16.671875,26.4166577 17.3307226,24.9192768 18.6484375,23.7265625 C19.9661524,22.5338482 21.6406148,21.9375 23.671875,21.9375 C25.8177191,21.9375 27.4999939,22.5052027 28.71875,23.640625 C29.9375061,24.7760473 30.546875,26.3541566 30.546875,28.375 C30.546875,29.3645883 30.2265657,30.322912 29.5859375,31.25 C28.9453093,32.177088 28.0729222,32.8697894 26.96875,33.328125 C28.2187562,33.7239603 29.1848924,34.3802037 29.8671875,35.296875 C30.5494826,36.2135462 30.890625,37.3333267 30.890625,38.65625 C30.890625,40.6979269 30.223965,42.3177023 28.890625,43.515625 C27.557285,44.7135477 25.8229273,45.3125 23.6875,45.3125 C21.5520727,45.3125 19.8151109,44.7343808 18.4765625,43.578125 C17.1380141,42.4218692 16.46875,40.8958428 16.46875,39 L19.375,39 C19.375,40.1979227 19.7656211,41.1562464 20.546875,41.875 C21.3281289,42.5937536 22.3749934,42.953125 23.6875,42.953125 C25.0833403,42.953125 26.151038,42.5885453 26.890625,41.859375 C27.630212,41.1302047 28,40.0833402 28,38.71875 C28,37.3958267 27.5937541,36.3802119 26.78125,35.671875 C25.9687459,34.9635381 24.7968827,34.5989584 23.265625,34.578125 L21.09375,34.578125 L21.09375,32.21875 Z"
four_d = "M29.09375,37.359375 L32.25,37.359375 L32.25,39.71875 L29.09375,39.71875 L29.09375,45 L26.1875,45 L26.1875,39.71875 L15.828125,39.71875 L15.828125,38.015625 L26.015625,22.25 L29.09375,22.25 L29.09375,37.359375 Z M19.109375,37.359375 L26.1875,37.359375 L26.1875,26.203125 L25.84375,26.828125 L19.109375,37.359375 Z"
five_d = "M18.21875,33.59375 L19.375,22.25 L31.03125,22.25 L31.03125,24.921875 L21.828125,24.921875 L21.140625,31.125 C22.2552139,30.4687467 23.5208262,30.140625 24.9375,30.140625 C27.010427,30.140625 28.6562439,30.825514 29.875,32.1953125 C31.0937561,33.565111 31.703125,35.416655 31.703125,37.75 C31.703125,40.0937617 31.0703188,41.9400974 29.8046875,43.2890625 C28.5390562,44.6380276 26.7708447,45.3125 24.5,45.3125 C22.4895733,45.3125 20.8489647,44.7552139 19.578125,43.640625 C18.3072853,42.5260361 17.5833342,40.9843848 17.40625,39.015625 L20.140625,39.015625 C20.3177092,40.3177148 20.7812463,41.2994759 21.53125,41.9609375 C22.2812537,42.6223991 23.2708272,42.953125 24.5,42.953125 C25.8437567,42.953125 26.8984337,42.4947963 27.6640625,41.578125 C28.4296913,40.6614537 28.8125,39.3958414 28.8125,37.78125 C28.8125,36.2604091 28.3984416,35.0390671 27.5703125,34.1171875 C26.7421834,33.1953079 25.6406319,32.734375 24.265625,32.734375 C23.005202,32.734375 22.0156286,33.0104139 21.296875,33.5625 L20.53125,34.1875 L18.21875,33.59375 Z"
six_d = "M28.234375,22.234375 L28.234375,24.6875 L27.703125,24.6875 C25.4531137,24.7291669 23.661465,25.3958269 22.328125,26.6875 C20.994785,27.9791731 20.2239594,29.7968633 20.015625,32.140625 C21.2135477,30.7656181 22.848948,30.078125 24.921875,30.078125 C26.9010516,30.078125 28.4817649,30.7760347 29.6640625,32.171875 C30.8463601,33.5677153 31.4375,35.3697806 31.4375,37.578125 C31.4375,39.9218867 30.7994855,41.796868 29.5234375,43.203125 C28.2473895,44.609382 26.5364691,45.3125 24.390625,45.3125 C22.2135308,45.3125 20.4479234,44.4765709 19.09375,42.8046875 C17.7395766,41.1328041 17.0625,38.9791798 17.0625,36.34375 L17.0625,35.234375 C17.0625,31.0468541 17.9557202,27.8463652 19.7421875,25.6328125 C21.5286548,23.4192598 24.1874823,22.2864586 27.71875,22.234375 L28.234375,22.234375 Z M24.4375,32.484375 C23.4479117,32.484375 22.5364625,32.781247 21.703125,33.375 C20.8697875,33.968753 20.2916683,34.7135372 19.96875,35.609375 L19.96875,36.671875 C19.96875,38.5468844 20.3906208,40.0572859 21.234375,41.203125 C22.0781292,42.3489641 23.130202,42.921875 24.390625,42.921875 C25.6927148,42.921875 26.7161421,42.4427131 27.4609375,41.484375 C28.2057329,40.5260369 28.578125,39.2708411 28.578125,37.71875 C28.578125,36.1562422 28.2005246,34.893234 27.4453125,33.9296875 C26.6901004,32.966141 25.6875062,32.484375 24.4375,32.484375 Z"
seven_points = "31.578125 23.875 22.15625 45 19.125 45 28.515625 24.625 16.203125 24.625 16.203125 22.25 31.578125 22.25"
eight_d = "M30.6875,28.1875 C30.6875,29.3229223 30.3880238,30.3333289 29.7890625,31.21875 C29.1901012,32.1041711 28.3802134,32.7968725 27.359375,33.296875 C28.5468809,33.8072942 29.4869757,34.5520784 30.1796875,35.53125 C30.8723993,36.5104216 31.21875,37.6197855 31.21875,38.859375 C31.21875,40.8281348 30.5546941,42.3958275 29.2265625,43.5625 C27.8984309,44.7291725 26.1510525,45.3125 23.984375,45.3125 C21.7968641,45.3125 20.0442774,44.7265684 18.7265625,43.5546875 C17.4088476,42.3828066 16.75,40.8177181 16.75,38.859375 C16.75,37.6302022 17.0859341,36.5208383 17.7578125,35.53125 C18.4296909,34.5416617 19.3593691,33.7916692 20.546875,33.28125 C19.5364533,32.7812475 18.7395862,32.0885461 18.15625,31.203125 C17.5729138,30.3177039 17.28125,29.3125056 17.28125,28.1875 C17.28125,26.2708237 17.8958272,24.7500056 19.125,23.625 C20.3541728,22.4999944 21.9739483,21.9375 23.984375,21.9375 C25.984385,21.9375 27.6015563,22.4999944 28.8359375,23.625 C30.0703187,24.7500056 30.6875,26.2708237 30.6875,28.1875 Z M28.328125,38.796875 C28.328125,37.5260353 27.9244832,36.4895873 27.1171875,35.6875 C26.3098918,34.8854127 25.2552148,34.484375 23.953125,34.484375 C22.6510352,34.484375 21.6067748,34.8802044 20.8203125,35.671875 C20.0338502,36.4635456 19.640625,37.5052019 19.640625,38.796875 C19.640625,40.0885481 20.0234337,41.104163 20.7890625,41.84375 C21.5546913,42.583337 22.6197848,42.953125 23.984375,42.953125 C25.3385484,42.953125 26.4010378,42.5807329 27.171875,41.8359375 C27.9427122,41.0911421 28.328125,40.0781314 28.328125,38.796875 Z M23.984375,24.3125 C22.8489527,24.3125 21.929691,24.664059 21.2265625,25.3671875 C20.523434,26.070316 20.171875,27.0260356 20.171875,28.234375 C20.171875,29.3906308 20.5182257,30.3255173 21.2109375,31.0390625 C21.9036493,31.7526077 22.8281192,32.109375 23.984375,32.109375 C25.1406308,32.109375 26.0651007,31.7526077 26.7578125,31.0390625 C27.4505243,30.3255173 27.796875,29.3906308 27.796875,28.234375 C27.796875,27.0781192 27.4375036,26.1354203 26.71875,25.40625 C25.9999964,24.6770797 25.0885472,24.3125 23.984375,24.3125 Z"
nine_d = "M27.96875,35 C27.3645803,35.7187536 26.6432334,36.2968728 25.8046875,36.734375 C24.9661416,37.1718772 24.04688,37.390625 23.046875,37.390625 C21.7343684,37.390625 20.5911507,37.0677116 19.6171875,36.421875 C18.6432243,35.7760384 17.8906277,34.8671934 17.359375,33.6953125 C16.8281223,32.5234316 16.5625,31.2291738 16.5625,29.8125 C16.5625,28.2916591 16.8515596,26.9218811 17.4296875,25.703125 C18.0078154,24.4843689 18.8281197,23.5520866 19.890625,22.90625 C20.9531303,22.2604134 22.1927012,21.9375 23.609375,21.9375 C25.8593863,21.9375 27.632806,22.7786374 28.9296875,24.4609375 C30.226569,26.1432376 30.875,28.4374855 30.875,31.34375 L30.875,32.1875 C30.875,36.6146055 30.0000087,39.846344 28.25,41.8828125 C26.4999913,43.919281 23.8593927,44.9635414 20.328125,45.015625 L19.765625,45.015625 L19.765625,42.578125 L20.375,42.578125 C22.7604286,42.5364581 24.5937436,41.9140685 25.875,40.7109375 C27.1562564,39.5078065 27.8541661,37.6041797 27.96875,35 Z M23.515625,35 C24.4843798,35 25.3776001,34.703128 26.1953125,34.109375 C27.0130249,33.515622 27.6093731,32.7812544 27.984375,31.90625 L27.984375,30.75 C27.984375,28.8541572 27.5729208,27.3125059 26.75,26.125 C25.9270792,24.9374941 24.885423,24.34375 23.625,24.34375 C22.3541603,24.34375 21.3333372,24.8307243 20.5625,25.8046875 C19.7916628,26.7786507 19.40625,28.062492 19.40625,29.65625 C19.40625,31.2083411 19.7786421,32.4869741 20.5234375,33.4921875 C21.2682329,34.4974009 22.2656188,35 23.515625,35 Z"
Now if you want to insert let's say 2047 you will do something like this:
# Import ActionChains from selenium
from selenium.webdriver.common.action_chains import ActionChains
# Find the required digits by XPATH
two = driver.find_element_by_xpath(f"//a[#class='key']/span/*/*/*[#d='{two_d}']") # for 2
zero = driver.find_element_by_xpath(f"//a[#class='key']/span/*/*/*[#d='{zero_d}']") # for 0
four = driver.find_element_by_xpath(f"//a[#class='key']/span/*/*/*[#d='{four_d}']") # for 4
seven = driver.find_element_by_xpath(f"//a[#class='key']/span/*/*/*[#points='{seven_points}']") # for 7
# Click on the digits using selenium ActionChains
ActionChains(driver).move_to_element(two).click().perform()
ActionChains(driver).move_to_element(zero).click().perform()
ActionChains(driver).move_to_element(four).click().perform()
ActionChains(driver).move_to_element(seven).click().perform()
I've tested this code using firefox driver. It should work with chrome drive as well.
I am trying to get all the href in the list in this website:https://nihongonosensei.net/?page_id=10246.
The website is very simple and clean. After reviewing the source, I found nothing dynamic.
However, if I do
import requests
url = 'https://nihongonosensei.net/?page_id=10246'
r = requests.get(url)
r.text
r.text only contains around 20000 characters information. More than half of the html is missing.
I tried to copy the whole HTML from "view page source" and directly load to Beautifulsoup:
from bs4 import BeautifulSoup
html = '' # too long to copy. Here is the link: view-source:https://nihongonosensei.net/?page_id=10246
soup = BeautifulSoup(html, 'html.parser')
Still only around 20000 characters are retained and the top half of the html is missing.
Here is my question:
Is there any character restrictions with requests and BeautifulSoup?
If so, how can I remove the limitation?
If not, why I cannot get the full html?
Thanks a lot!
Rachel
import requests
from bs4 import BeautifulSoup
r = requests.get("https://nihongonosensei.net/?page_id=10246")
soup = BeautifulSoup(r.text, 'html.parser')
for item in soup.findAll("a", href=True):
item = item.get("href")
if item.startswith("http"):
print(item)
output:
https://nihongonosensei.net/
http://nihongonosensei.net/?p=3547
http://nihongonosensei.net/?p=3563
http://nihongonosensei.net/?p=3568
http://nihongonosensei.net/?p=3600
http://nihongonosensei.net/?p=3614
http://nihongonosensei.net/?p=3618
http://nihongonosensei.net/?p=3622
http://nihongonosensei.net/?p=3626
http://nihongonosensei.net/?p=3633
http://nihongonosensei.net/?p=3695
http://nihongonosensei.net/?p=3697
http://nihongonosensei.net/?p=3702
http://nihongonosensei.net/?p=3707
http://nihongonosensei.net/?p=3710
http://nihongonosensei.net/?p=3712
http://nihongonosensei.net/?p=3714
http://nihongonosensei.net/?p=3719
http://nihongonosensei.net/?p=3722
http://nihongonosensei.net/?p=3726
http://nihongonosensei.net/?p=3730
http://nihongonosensei.net/?p=3733
http://nihongonosensei.net/?p=3735
http://nihongonosensei.net/?p=5236
http://nihongonosensei.net/?p=5238
http://nihongonosensei.net/?p=5240
http://nihongonosensei.net/?p=5244
http://nihongonosensei.net/?p=5618
http://nihongonosensei.net/?p=5620
http://nihongonosensei.net/?p=5961
http://nihongonosensei.net/?p=5965
http://nihongonosensei.net/?p=5967
http://nihongonosensei.net/?p=5970
http://nihongonosensei.net/?p=5972
http://nihongonosensei.net/?p=6772
http://nihongonosensei.net/?p=7977
http://nihongonosensei.net/?p=7979
http://nihongonosensei.net/?p=7983
http://nihongonosensei.net/?p=7985
http://nihongonosensei.net/?p=7987
http://nihongonosensei.net/?p=8869
http://nihongonosensei.net/?p=8891
http://nihongonosensei.net/?p=9192
http://nihongonosensei.net/?p=9197
http://nihongonosensei.net/?p=9198
http://nihongonosensei.net/?p=9199
http://nihongonosensei.net/?p=9219
http://nihongonosensei.net/?p=9221
http://nihongonosensei.net/?p=9223
http://nihongonosensei.net/?p=9249
http://nihongonosensei.net/?p=9280
http://nihongonosensei.net/?p=9320
http://nihongonosensei.net/?p=9322
http://nihongonosensei.net/?p=9324
http://nihongonosensei.net/?p=9327
http://nihongonosensei.net/?p=9329
http://nihongonosensei.net/?p=9353
http://nihongonosensei.net/?p=9359
http://nihongonosensei.net/?p=9360
http://nihongonosensei.net/?p=13973
http://nihongonosensei.net/?p=13972
http://nihongonosensei.net/?p=13974
http://nihongonosensei.net/?p=11851
http://nihongonosensei.net/?p=11858
http://nihongonosensei.net/?p=12202
http://nihongonosensei.net/?p=12999
http://nihongonosensei.net/?p=13112
http://nihongonosensei.net/?p=13364
http://nihongonosensei.net/?p=13494
http://nihongonosensei.net/?p=14887
http://nihongonosensei.net/?p=14889
http://nihongonosensei.net/?p=14915
http://nihongonosensei.net/?p=14918
http://nihongonosensei.net/?p=17745
http://nihongonosensei.net/?p=18155
http://nihongonosensei.net/?p=18159
http://nihongonosensei.net/?p=18188
http://nihongonosensei.net/?p=18206
http://nihongonosensei.net/?p=18204
http://nihongonosensei.net/?p=18223
http://nihongonosensei.net/?p=18407
http://nihongonosensei.net/?p=18460
http://nihongonosensei.net/?p=18461
http://nihongonosensei.net/?p=18578
http://nihongonosensei.net/?p=18611
http://nihongonosensei.net/?p=18696
http://nihongonosensei.net/?p=18705
http://nihongonosensei.net/?p=18707
http://nihongonosensei.net/?p=18763
http://nihongonosensei.net/?p=3738
http://nihongonosensei.net/?p=3745
http://nihongonosensei.net/?p=3759
http://nihongonosensei.net/?p=3776
http://nihongonosensei.net/?p=3778
http://nihongonosensei.net/?p=3781
http://nihongonosensei.net/?p=3783
http://nihongonosensei.net/?p=3785
http://nihongonosensei.net/?p=3797
http://nihongonosensei.net/?p=3799
http://nihongonosensei.net/?p=3801
http://nihongonosensei.net/?p=3804
http://nihongonosensei.net/?p=3809
http://nihongonosensei.net/?p=3824
http://nihongonosensei.net/?p=3826
http://nihongonosensei.net/?p=13941
http://nihongonosensei.net/?p=3833
http://nihongonosensei.net/?p=4097
http://nihongonosensei.net/?p=5058
http://nihongonosensei.net/?p=5246
http://nihongonosensei.net/?p=5248
http://nihongonosensei.net/?p=5251
http://nihongonosensei.net/?p=5253
http://nihongonosensei.net/?p=5255
http://nihongonosensei.net/?p=5616
http://nihongonosensei.net/?p=5614
http://nihongonosensei.net/?p=5978
http://nihongonosensei.net/?p=5982
http://nihongonosensei.net/?p=5974
http://nihongonosensei.net/?p=6203
http://nihongonosensei.net/?p=6205
http://nihongonosensei.net/?p=11829
http://nihongonosensei.net/?p=11830
http://nihongonosensei.net/?p=6209
http://nihongonosensei.net/?p=6211
http://nihongonosensei.net/?p=7909
http://nihongonosensei.net/?p=7970
http://nihongonosensei.net/?p=7972
http://nihongonosensei.net/?p=7974
http://nihongonosensei.net/?p=7990
http://nihongonosensei.net/?p=7992
http://nihongonosensei.net/?p=8008
http://nihongonosensei.net/?p=8010
http://nihongonosensei.net/?p=8012
http://nihongonosensei.net/?p=9447
http://nihongonosensei.net/?p=9452
http://nihongonosensei.net/?p=9876
http://nihongonosensei.net/?p=9884
http://nihongonosensei.net/?p=9890
http://nihongonosensei.net/?p=9891
http://nihongonosensei.net/?p=9945
http://nihongonosensei.net/?p=14072
http://nihongonosensei.net/?p=14073
http://nihongonosensei.net/?p=10533
http://nihongonosensei.net/?p=10532
http://nihongonosensei.net/?p=11855
http://nihongonosensei.net/?p=11521
http://nihongonosensei.net/?p=18734
http://nihongonosensei.net/?p=18726
http://nihongonosensei.net/?p=11862
http://nihongonosensei.net/?p=11864
http://nihongonosensei.net/?p=11866
http://nihongonosensei.net/?p=12025
http://nihongonosensei.net/?p=12027
http://nihongonosensei.net/?p=12115
http://nihongonosensei.net/?p=13076
http://nihongonosensei.net/?p=13142
http://nihongonosensei.net/?p=13145
http://nihongonosensei.net/?p=13453
http://nihongonosensei.net/?p=13456
http://nihongonosensei.net/?p=13459
http://nihongonosensei.net/?p=13479
http://nihongonosensei.net/?p=13483
http://nihongonosensei.net/?p=3535
http://nihongonosensei.net/?p=14896
http://nihongonosensei.net/?p=18263
http://nihongonosensei.net/?p=18324
http://nihongonosensei.net/?p=18366
http://nihongonosensei.net/?p=18373
http://nihongonosensei.net/?p=18381
http://nihongonosensei.net/?p=18398
http://nihongonosensei.net/?p=18680
http://nihongonosensei.net/?p=18682
http://nihongonosensei.net/?p=18684
http://nihongonosensei.net/?p=1700
http://nihongonosensei.net/?p=1708
http://nihongonosensei.net/?p=1713
http://nihongonosensei.net/?p=1718
http://nihongonosensei.net/?p=1735
http://nihongonosensei.net/?p=1742
http://nihongonosensei.net/?p=1745
http://nihongonosensei.net/?p=1748
http://nihongonosensei.net/?p=1752
http://nihongonosensei.net/?p=1755
http://nihongonosensei.net/?p=1758
http://nihongonosensei.net/?p=1761
http://nihongonosensei.net/?p=1764
http://nihongonosensei.net/?p=1767
http://nihongonosensei.net/?p=1770
http://nihongonosensei.net/?p=1773
http://nihongonosensei.net/?p=1777
http://nihongonosensei.net/?p=1782
http://nihongonosensei.net/?p=1785
http://nihongonosensei.net/?p=1788
http://nihongonosensei.net/?p=1791
http://nihongonosensei.net/?p=1794
http://nihongonosensei.net/?p=1797
http://nihongonosensei.net/?p=1801
http://nihongonosensei.net/?p=1804
http://nihongonosensei.net/?p=1807
http://nihongonosensei.net/?p=1810
http://nihongonosensei.net/?p=1813
http://nihongonosensei.net/?p=1816
http://nihongonosensei.net/?p=1819
http://nihongonosensei.net/?p=1823
http://nihongonosensei.net/?p=1828
http://nihongonosensei.net/?p=1835
http://nihongonosensei.net/?p=1838
http://nihongonosensei.net/?p=12082
http://nihongonosensei.net/?p=3470
http://nihongonosensei.net/?p=3477
http://nihongonosensei.net/?p=3484
http://nihongonosensei.net/?p=3492
http://nihongonosensei.net/?p=3553
http://nihongonosensei.net/?p=3559
http://nihongonosensei.net/?p=13970
http://nihongonosensei.net/?p=6331
http://nihongonosensei.net/?p=6335
http://nihongonosensei.net/?p=6339
http://nihongonosensei.net/?p=6341
http://nihongonosensei.net/?p=6769
http://nihongonosensei.net/?p=8506
http://nihongonosensei.net/?p=8857
http://nihongonosensei.net/?p=9283
http://nihongonosensei.net/?p=9306
http://nihongonosensei.net/?p=9308
http://nihongonosensei.net/?p=9312
http://nihongonosensei.net/?p=9314
http://nihongonosensei.net/?p=9422
http://nihongonosensei.net/?p=9462
http://nihongonosensei.net/?p=9860
http://nihongonosensei.net/?p=11635
http://nihongonosensei.net/?p=12073
http://nihongonosensei.net/?p=12784
http://nihongonosensei.net/?p=12795
http://nihongonosensei.net/?p=12821
http://nihongonosensei.net/?p=12824
http://nihongonosensei.net/?p=12830
http://nihongonosensei.net/?p=12832
http://nihongonosensei.net/?p=12834
http://nihongonosensei.net/?p=12987
http://nihongonosensei.net/?p=12995
http://nihongonosensei.net/?p=13018
http://nihongonosensei.net/?p=3761
http://nihongonosensei.net/?p=13326
http://nihongonosensei.net/?p=13327
http://nihongonosensei.net/?p=13340
http://nihongonosensei.net/?p=13344
http://nihongonosensei.net/?p=17748
http://nihongonosensei.net/?p=17758
http://nihongonosensei.net/?p=17767
http://nihongonosensei.net/?p=17771
http://nihongonosensei.net/?p=18162
http://nihongonosensei.net/?p=18165
http://nihongonosensei.net/?p=18171
http://nihongonosensei.net/?p=18202
http://nihongonosensei.net/?p=18199
http://nihongonosensei.net/?p=18314
http://nihongonosensei.net/?p=18312
http://nihongonosensei.net/?p=18399
http://nihongonosensei.net/?p=18400
http://nihongonosensei.net/?p=18585
http://nihongonosensei.net/?p=18589
http://nihongonosensei.net/?p=18591
http://nihongonosensei.net/?p=18301
http://nihongonosensei.net/?p=18701
http://nihongonosensei.net/?p=18773
http://nihongonosensei.net/?p=18775
http://nihongonosensei.net/?p=18788
http://nihongonosensei.net/?p=18790
http://nihongonosensei.net/?p=18792
http://nihongonosensei.net/?p=18821
http://nihongonosensei.net/?p=3571
http://nihongonosensei.net/?p=9936
http://nihongonosensei.net/?p=3578
http://nihongonosensei.net/?p=5980
http://nihongonosensei.net/?p=3609
http://nihongonosensei.net/?p=3680
http://nihongonosensei.net/?p=3828
http://nihongonosensei.net/?p=6345
http://nihongonosensei.net/?p=6347
http://nihongonosensei.net/?p=6351
http://nihongonosensei.net/?p=7905
http://nihongonosensei.net/?p=7907
http://nihongonosensei.net/?p=8063
http://nihongonosensei.net/?p=18470
http://nihongonosensei.net/?p=18471
http://nihongonosensei.net/?p=9425
http://nihongonosensei.net/?p=9426
http://nihongonosensei.net/?p=9465
http://nihongonosensei.net/?p=9466
http://nihongonosensei.net/?p=9872
http://nihongonosensei.net/?p=10058
http://nihongonosensei.net/?p=11304
http://nihongonosensei.net/?p=11948
http://nihongonosensei.net/?p=18497
http://nihongonosensei.net/?p=18499
http://nihongonosensei.net/?p=18501
http://nihongonosensei.net/?p=12143
http://nihongonosensei.net/?p=12789
http://nihongonosensei.net/?p=12882
http://nihongonosensei.net/?p=12885
http://nihongonosensei.net/?p=12886
http://nihongonosensei.net/?p=13074
http://nihongonosensei.net/?p=13087
http://nihongonosensei.net/?p=13092
http://nihongonosensei.net/?p=13136
http://nihongonosensei.net/?p=13151
http://nihongonosensei.net/?p=13371
http://nihongonosensei.net/?p=18157
http://nihongonosensei.net/?p=18219
http://nihongonosensei.net/?p=18221
http://nihongonosensei.net/?p=18266
http://nihongonosensei.net/?p=18292
http://nihongonosensei.net/?p=18293
http://nihongonosensei.net/?p=18392
http://nihongonosensei.net/?p=18488
http://nihongonosensei.net/?p=18489
http://nihongonosensei.net/?p=18593
http://nihongonosensei.net/?p=18595
http://nihongonosensei.net/?p=18612
http://nihongonosensei.net/?p=18613
http://nihongonosensei.net/?p=18657
http://nihongonosensei.net/?p=18659
http://nihongonosensei.net/?p=18662
http://nihongonosensei.net/?p=18664
http://nihongonosensei.net/?p=12827
http://nihongonosensei.net/?p=4094
http://nihongonosensei.net/?p=18732
http://nihongonosensei.net/?p=18728
http://nihongonosensei.net/?p=18720
http://nihongonosensei.net/?p=18722
http://nihongonosensei.net/?p=18730
http://nihongonosensei.net/?p=18724
http://nihongonosensei.net/?p=4094
http://nihongonosensei.net/?p=3500
http://nihongonosensei.net/?p=3526
http://nihongonosensei.net/?p=3529
http://nihongonosensei.net/?p=3474
http://nihongonosensei.net/?p=3585
http://nihongonosensei.net/?p=3606
http://nihongonosensei.net/?p=3643
http://nihongonosensei.net/?p=3650
http://nihongonosensei.net/?p=3656
http://nihongonosensei.net/?p=5062
http://nihongonosensei.net/?p=5941
http://nihongonosensei.net/?p=5943
http://nihongonosensei.net/?p=5945
http://nihongonosensei.net/?p=5947
http://nihongonosensei.net/?p=5949
http://nihongonosensei.net/?p=5984
http://nihongonosensei.net/?p=7024
http://nihongonosensei.net/?p=7026
http://nihongonosensei.net/?p=7096
http://nihongonosensei.net/?p=7098
http://nihongonosensei.net/?p=7100
http://nihongonosensei.net/?p=7102
http://nihongonosensei.net/?p=7104
http://nihongonosensei.net/?p=7152
http://nihongonosensei.net/?p=10116
http://nihongonosensei.net/?p=3550
http://nihongonosensei.net/?p=8048
http://nihongonosensei.net/?p=6349
http://nihongonosensei.net/?p=8051
http://nihongonosensei.net/?p=8058
http://nihongonosensei.net/?p=8061
http://nihongonosensei.net/?p=8070
http://nihongonosensei.net/?p=8080
http://nihongonosensei.net/?p=8082
http://nihongonosensei.net/?p=4085
http://nihongonosensei.net/?p=4088
http://nihongonosensei.net/?p=8540
http://nihongonosensei.net/?p=8542
http://nihongonosensei.net/?p=8558
http://nihongonosensei.net/?p=8564
http://nihongonosensei.net/?p=8665
http://nihongonosensei.net/?p=8669
http://nihongonosensei.net/?p=8672
http://nihongonosensei.net/?p=8675
http://nihongonosensei.net/?p=8710
http://nihongonosensei.net/?p=8705
http://nihongonosensei.net/?p=7981
http://nihongonosensei.net/?p=8724
http://nihongonosensei.net/?p=8730
http://nihongonosensei.net/?p=8733
http://nihongonosensei.net/?p=8856
http://nihongonosensei.net/?p=9310
http://nihongonosensei.net/?p=9352
http://nihongonosensei.net/?p=5242
http://nihongonosensei.net/?p=9385
http://nihongonosensei.net/?p=9386
http://nihongonosensei.net/?p=9488
http://nihongonosensei.net/?p=9487
http://nihongonosensei.net/?p=12075
http://nihongonosensei.net/?p=18193
http://nihongonosensei.net/?p=18350
http://nihongonosensei.net/?p=18351
http://nihongonosensei.net/?p=18406
http://nihongonosensei.net/?p=18428
http://nihongonosensei.net/?p=18447
http://nihongonosensei.net/?p=18587
http://nihongonosensei.net/?p=18698
http://nihongonosensei.net/?p=18695
http://nihongonosensei.net/?p=18703
http://nihongonosensei.net/?p=3659
http://nihongonosensei.net/?p=3673
http://nihongonosensei.net/?p=3676
http://nihongonosensei.net/?p=3683
http://nihongonosensei.net/?p=3686
http://nihongonosensei.net/?p=18190
http://nihongonosensei.net/?p=3747
http://nihongonosensei.net/?p=3749
http://nihongonosensei.net/?p=3753
http://nihongonosensei.net/?p=5951
http://nihongonosensei.net/?p=5953
http://nihongonosensei.net/?p=5955
http://nihongonosensei.net/?p=5957
http://nihongonosensei.net/?p=7068
http://nihongonosensei.net/?p=7071
http://nihongonosensei.net/?p=7075
http://nihongonosensei.net/?p=7121
http://nihongonosensei.net/?p=3541
http://nihongonosensei.net/?p=8004
http://nihongonosensei.net/?p=6343
http://nihongonosensei.net/?p=8144
http://nihongonosensei.net/?p=8143
http://nihongonosensei.net/?p=8150
http://nihongonosensei.net/?p=8152
http://nihongonosensei.net/?p=8161
http://nihongonosensei.net/?p=8164
http://nihongonosensei.net/?p=8257
http://nihongonosensei.net/?p=9482
http://nihongonosensei.net/?p=8261
http://nihongonosensei.net/?p=8159
http://nihongonosensei.net/?p=8272
http://nihongonosensei.net/?p=8274
http://nihongonosensei.net/?p=8277
http://nihongonosensei.net/?p=8279
http://nihongonosensei.net/?p=9215
http://nihongonosensei.net/?p=9217
http://nihongonosensei.net/?p=9859
http://nihongonosensei.net/?p=10102
http://nihongonosensei.net/?p=18631
http://nihongonosensei.net/?p=18632
http://nihongonosensei.net/?p=11303
http://nihongonosensei.net/?p=12781
http://nihongonosensei.net/?p=12812
http://nihongonosensei.net/?p=12799
http://nihongonosensei.net/?p=12802
http://nihongonosensei.net/?p=12809
http://nihongonosensei.net/?p=13150
http://nihongonosensei.net/?p=11946
http://nihongonosensei.net/?p=13152
http://nihongonosensei.net/?p=18503
http://nihongonosensei.net/?p=3582
http://nihongonosensei.net/?p=17664
http://nihongonosensei.net/?p=17751
http://nihongonosensei.net/?p=18264
http://nihongonosensei.net/?p=18267
http://nihongonosensei.net/?p=18265
http://nihongonosensei.net/?p=18303
http://nihongonosensei.net/?p=18393
http://nihongonosensei.net/?p=8281
http://nihongonosensei.net/?p=18614
http://nihongonosensei.net/?p=18676
http://nihongonosensei.net/?p=18678
http://nihongonosensei.net/?p=18816
http://nihongonosensei.net/?p=18818
http://nihongonosensei.net/?p=18812
http://nihongonosensei.net/?p=18809
http://nihongonosensei.net/?p=18807
http://nihongonosensei.net/?p=18805
http://nihongonosensei.net/?p=18803
http://nihongonosensei.net/?p=18330
http://nihongonosensei.net/?p=3446
http://nihongonosensei.net/?p=3662
http://nihongonosensei.net/?p=5182
http://nihongonosensei.net/?p=9262
http://nihongonosensei.net/?p=9264
http://nihongonosensei.net/?p=3647
http://nihongonosensei.net/?p=8567
http://nihongonosensei.net/?p=9343
http://nihongonosensei.net/?p=8045
http://nihongonosensei.net/?p=18305
http://nihongonosensei.net/?p=18307
http://nihongonosensei.net/?p=18427
http://nihongonosensei.net/?p=18615
http://nihongonosensei.net/?p=18713
http://nihongonosensei.net/?p=18715
http://nihongonosensei.net/?p=18717
http://nihongonosensei.net/?p=18736
http://nihongonosensei.net/?p=3668
http://nihongonosensei.net/?p=5180
http://nihongonosensei.net/?p=4090
http://nihongonosensei.net/?p=11943
http://nihongonosensei.net/?p=11950
http://nihongonosensei.net/?p=11941
http://nihongonosensei.net/?p=12816
http://nihongonosensei.net/?p=18323
http://nihongonosensei.net/?p=18349
http://nihongonosensei.net/?p=18784
http://nihongonosensei.net/?p=18786
http://nihongonosensei.net/?p=18814
http://nihongonosensei.net/?p=18405
http://nihongonosensei.net/?p=5233
http://nihongonosensei.net/?p=7154
http://nihongonosensei.net/?p=7938
http://nihongonosensei.net/?p=7943
http://nihongonosensei.net/?p=8509
http://nihongonosensei.net/?p=8541
http://nihongonosensei.net/?p=8886
http://nihongonosensei.net/?p=8889
http://nihongonosensei.net/?p=9440
http://nihongonosensei.net/?p=9441
http://nihongonosensei.net/?p=3639
http://nihongonosensei.net/?p=3575
http://nihongonosensei.net/?p=3603
http://nihongonosensei.net/?p=11627
http://nihongonosensei.net/?p=11953
http://nihongonosensei.net/?p=11955
http://nihongonosensei.net/?p=17914
http://nihongonosensei.net/?p=18195
http://nihongonosensei.net/?p=18217
http://nihongonosensei.net/?p=18348
http://nihongonosensei.net/?p=18371
http://nihongonosensei.net/?p=18375
http://nihongonosensei.net/?p=18377
http://nihongonosensei.net/?p=18379
http://nihongonosensei.net/?p=18653
http://nihongonosensei.net/?p=18655
http://nihongonosensei.net/?p=13346
http://nihongonosensei.net/?p=13347
http://nihongonosensei.net/?p=13348
http://nihongonosensei.net/?p=13358
http://nihongonosensei.net/?p=13362
http://nihongonosensei.net/?p=13373
http://nihongonosensei.net/?p=13369
http://nihongonosensei.net/?p=13379
http://nihongonosensei.net/?p=13385
http://nihongonosensei.net/?p=13462
http://nihongonosensei.net/?p=13466
http://nihongonosensei.net/?p=14905
http://nihongonosensei.net/?p=17576
http://nihongonosensei.net/?p=17593
http://nihongonosensei.net/?p=17597
http://nihongonosensei.net/?p=17600
http://nihongonosensei.net/?p=17917
http://nihongonosensei.net/?p=18268
http://nihongonosensei.net/?p=18363
http://nihongonosensei.net/?p=19118
http://nihongonosensei.net/
http://nihongonosensei.net/?cat=7
http://nihongonosensei.net/?cat=3
http://nihongonosensei.net/?page_id=10246
http://nihongonosensei.net/?page_id=10246#linkn1
http://nihongonosensei.net/?page_id=10246#linkn2
http://nihongonosensei.net/?page_id=10246#linkn3
http://nihongonosensei.net/?page_id=10246#linkn4n5
http://nihongonosensei.net/?page_id=10246#linkn0
http://nihongonosensei.net/?page_id=13879
http://nihongonosensei.net/?page_id=8874
http://nihongonosensei.net/?p=17729
http://nihongonosensei.net/?page_id=8874#link2019
http://nihongonosensei.net/?page_id=8874#link30
http://nihongonosensei.net/?page_id=8874#link29
http://nihongonosensei.net/?page_id=8874#link28
http://nihongonosensei.net/?page_id=8874#link27
http://nihongonosensei.net/?page_id=8874#link26
http://nihongonosensei.net/?page_id=8874#link25
http://nihongonosensei.net/?page_id=8874#link24
http://nihongonosensei.net/?page_id=8874#link23
http://nihongonosensei.net/?page_id=4945
http://nihongonosensei.net/?page_id=5094
http://nihongonosensei.net/?page_id=13794
http://nihongonosensei.net/?page_id=13794#link1
http://nihongonosensei.net/?page_id=13794#link2
http://nihongonosensei.net/?page_id=13825
http://nihongonosensei.net/?page_id=13827
http://nihongonosensei.net/?page_id=1904
https://thk.kanzae.net/
I'm trying to grab just the first href in each row in an HTML table. Using find_all on the soup object doesn't work because there are multiple tables so I used soup.select() to isolate just that table and work from there but it doesn't seem to be working.
Tried using find_all on the soup object alone, tried looping through the table rows with find() but it said that it returns 'NoneType'.
I Would like to be able to store a list that starts [/players/a/abrinal01.html, "/players/a/acyqu01.html, etc]
url = 'https://www.basketball-reference.com/leagues/NBA_2019_per_game.html'
res = requests.get(url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
table = soup.find("table", { "id" : "per_game_stats" })
You can access the desired data by anchoring the parsing from the outer div wrapper with the id of all_per_game_stats:
import requests
from bs4 import BeautifulSoup as soup
d = soup(requests.get('https://www.basketball-reference.com/leagues/NBA_2019_per_game.html').text, 'html.parser')
data = [b.td.a['href'] for b in d.find('div', {'id':'all_per_game_stats'}).table.find_all('tr') if b.td]
Output:
['/players/a/abrinal01.html', '/players/a/acyqu01.html', '/players/a/adamsja01.html', '/players/a/adamsst01.html', '/players/a/adebaba01.html', '/players/a/adelde01.html', '/players/a/akoonde01.html', '/players/a/aldrila01.html', '/players/a/alkinra01.html', '/players/a/allengr01.html', '/players/a/allenja01.html', '/players/a/allenka01.html', '/players/a/aminual01.html', '/players/a/anderju01.html', '/players/a/anderky01.html', '/players/a/anderry01.html', '/players/a/anderry01.html', '/players/a/anderry01.html', '/players/a/anigbik01.html', '/players/a/antetgi01.html', '/players/a/antetko01.html', '/players/a/anthoca01.html', '/players/a/anunoog01.html', '/players/a/arcidry01.html', '/players/a/arizatr01.html', '/players/a/arizatr01.html', '/players/a/arizatr01.html', '/players/a/augusdj01.html', '/players/a/aytonde01.html', '/players/b/bacondw01.html', '/players/b/baglema01.html', '/players/b/bakerro01.html', '/players/b/bakerro01.html', '/players/b/bakerro01.html', '/players/b/baldwwa01.html', '/players/b/balllo01.html', '/players/b/bambamo01.html', '/players/b/bareajo01.html', '/players/b/barneha02.html', '/players/b/barneha02.html', '/players/b/barneha02.html', '/players/b/bartowi01.html', '/players/b/bateske01.html', '/players/b/batumni01.html', '/players/b/bayleje01.html', '/players/b/baynear01.html', '/players/b/bazemke01.html', '/players/b/bealbr01.html', '/players/b/beaslma01.html', '/players/b/beaslmi01.html', '/players/b/belinma01.html', '/players/b/belljo01.html', '/players/b/bembrde01.html', '/players/b/bendedr01.html', '/players/b/bertada02.html', '/players/b/bertada01.html', '/players/b/beverpa01.html', '/players/b/birchkh01.html', '/players/b/biyombi01.html', '/players/b/bjeline01.html', '/players/b/blakean01.html', '/players/b/bledser01.html', '/players/b/blossja01.html', '/players/b/bogdabo01.html', '/players/b/bogdabo02.html', '/players/b/bogutan01.html', '/players/b/boldejo01.html', '/players/b/bongais01.html', '/players/b/bookede01.html', '/players/b/bouchch01.html', '/players/b/bradlav01.html', '/players/b/bradlav01.html', '/players/b/bradlav01.html', '/players/b/bradlto01.html', '/players/b/breweco01.html', '/players/b/breweco01.html', '/players/b/breweco01.html', '/players/b/bridgmi01.html', '/players/b/bridgmi02.html', '/players/b/briscis01.html', '/players/b/broekry01.html', '/players/b/brogdma01.html', '/players/b/brookdi01.html', '/players/b/brookma01.html', '/players/b/brownbr01.html', '/players/b/brownja02.html', '/players/b/brownlo01.html', '/players/b/brownst02.html', '/players/b/browntr01.html', '/players/b/brunsja01.html', '/players/b/bryanth01.html', '/players/b/bullore01.html', '/players/b/bullore01.html', '/players/b/bullore01.html', '/players/b/burketr01.html', '/players/b/burketr01.html', '/players/b/burketr01.html', '/players/b/burksal01.html', '/players/b/burksal01.html', '/players/b/burksal01.html', '/players/b/burksal01.html', '/players/b/burtode02.html', '/players/b/butleji01.html', '/players/b/butleji01.html', '/players/b/butleji01.html', '/players/c/cabocbr01.html', '/players/c/caldejo01.html', '/players/c/caldwke01.html', '/players/c/canaais01.html', '/players/c/canaais01.html', '/players/c/canaais01.html', '/players/c/canaais01.html', '/players/c/capelca01.html', '/players/c/carrode01.html', '/players/c/carteje01.html', '/players/c/cartevi01.html', '/players/c/cartewe01.html', '/players/c/cartemi01.html', '/players/c/cartemi01.html', '/players/c/cartemi01.html', '/players/c/carusal01.html', '/players/c/casspom01.html', '/players/c/caulewi01.html', '/players/c/caupatr01.html', '/players/c/cavanty01.html', '/players/c/chandty01.html', '/players/c/chandty01.html', '/players/c/chandty01.html', '/players/c/chandwi01.html', '/players/c/chandwi01.html', '/players/c/chandwi01.html', '/players/c/chealjo01.html', '/players/c/chiozch01.html', '/players/c/chrisma01.html', '/players/c/chrisma01.html', '/players/c/chrisma01.html', '/players/c/clarkga01.html', '/players/c/clarkia01.html', '/players/c/clarkjo01.html', '/players/c/collijo01.html', '/players/c/colliza01.html', '/players/c/collida01.html', '/players/c/colsobo01.html', '/players/c/conlemi01.html', '/players/c/connapa01.html', '/players/c/cookqu01.html', '/players/c/couside01.html', '/players/c/covinro01.html', '/players/c/covinro01.html', '/players/c/covinro01.html', '/players/c/crabbal01.html', '/players/c/craigto01.html', '/players/c/crawfja01.html', '/players/c/creekmi01.html', '/players/c/creekmi01.html', '/players/c/creekmi01.html', '/players/c/crowdja01.html', '/players/c/cunnida01.html', '/players/c/curryse01.html', '/players/c/curryst01.html', '/players/d/danietr01.html', '/players/d/davisan02.html', '/players/d/davisde01.html', '/players/d/davised01.html', '/players/d/davisty01.html', '/players/d/dedmode01.html', '/players/d/dekkesa01.html', '/players/d/dekkesa01.html', '/players/d/dekkesa01.html', '/players/d/delgaan01.html', '/players/d/dellama01.html', '/players/d/dellama01.html', '/players/d/dellama01.html', '/players/d/denglu01.html', '/players/d/derozde01.html', '/players/d/derrima01.html', '/players/d/diallch01.html', '/players/d/diallha01.html', '/players/d/dienggo01.html', '/players/d/dinwisp01.html', '/players/d/divindo01.html', '/players/d/doncilu01.html', '/players/d/dorsety01.html', '/players/d/dorsety01.html', '/players/d/dorsety01.html', '/players/d/dotsoda01.html', '/players/d/doziepj01.html', '/players/d/dragigo01.html', '/players/d/drumman01.html', '/players/d/dudleja01.html', '/players/d/dunnkr01.html', '/players/d/duranke01.html', '/players/d/duvaltr01.html', '/players/e/edwarvi01.html', '/players/e/ellenhe01.html', '/players/e/ellenhe01.html', '/players/e/ellenhe01.html', '/players/e/ellinwa01.html', '/players/e/ellinwa01.html', '/players/e/ellinwa01.html', '/players/e/embiijo01.html', '/players/e/ennisja01.html', '/players/e/ennisja01.html', '/players/e/ennisja01.html', '/players/e/eubandr01.html', '/players/e/evansja02.html', '/players/e/evansja01.html', '/players/e/evansja01.html', '/players/e/evansja01.html', '/players/e/evansty01.html', '/players/e/exumda01.html', '/players/f/farieke01.html', '/players/f/farieke01.html', '/players/f/farieke01.html', '/players/f/favorde01.html', '/players/f/feliccr01.html', '/players/f/feltora01.html', '/players/f/fergute01.html', '/players/f/ferreyo01.html', '/players/f/finnedo01.html', '/players/f/forbebr01.html', '/players/f/fournev01.html', '/players/f/foxde01.html', '/players/f/frazime01.html', '/players/f/fraziti01.html', '/players/f/fraziti01.html', '/players/f/fraziti01.html', '/players/f/fredeji01.html', '/players/f/fryech01.html', '/players/f/fultzma01.html', '/players/g/gallida01.html', '/players/g/gallola01.html', '/players/g/garrebi01.html', '/players/g/gasolma01.html', '/players/g/gasolma01.html', '/players/g/gasolma01.html', '/players/g/gasolpa01.html', '/players/g/gasolpa01.html', '/players/g/gasolpa01.html', '/players/g/gayru01.html', '/players/g/georgpa01.html', '/players/g/gibsota01.html', '/players/g/gilesha01.html', '/players/g/gilgesh01.html', '/players/g/goberru01.html', '/players/g/goodwbr01.html', '/players/g/gordoaa01.html', '/players/g/gordoer01.html', '/players/g/gortama01.html', '/players/g/grahade01.html', '/players/g/grahatr01.html', '/players/g/grantje01.html', '/players/g/grantje02.html', '/players/g/grantdo01.html', '/players/g/greenda02.html', '/players/g/greendr01.html', '/players/g/greenge01.html', '/players/g/greenja01.html', '/players/g/greenja01.html', '/players/g/greenja01.html', '/players/g/greenje02.html', '/players/g/griffbl01.html', '/players/h/hamilda02.html', '/players/h/hannadu01.html', '/players/h/hardati02.html', '/players/h/hardati02.html', '/players/h/hardati02.html', '/players/h/hardeja01.html', '/players/h/harklma01.html', '/players/h/harremo01.html', '/players/h/harride01.html', '/players/h/harriga01.html', '/players/h/harrijo01.html', '/players/h/harrito02.html', '/players/h/harrito02.html', '/players/h/harrito02.html', '/players/h/harrian01.html', '/players/h/harrian01.html', '/players/h/harrian01.html', '/players/h/harrian01.html', '/players/h/harrish01.html', '/players/h/hartjo01.html', '/players/h/harteis01.html', '/players/h/hasleud01.html', '/players/h/haywago01.html', '/players/h/hensojo01.html', '/players/h/hernaju01.html', '/players/h/hernawi01.html', '/players/h/hezonma01.html', '/players/h/hicksis01.html', '/players/h/hieldbu01.html', '/players/h/highsha01.html', '/players/h/hilarne01.html', '/players/h/hillge01.html', '/players/h/hillge01.html', '/players/h/hillge01.html', '/players/h/hillso01.html', '/players/h/holidaa01.html', '/players/h/holidjr01.html', '/players/h/holidju01.html', '/players/h/holidju01.html', '/players/h/holidju01.html', '/players/h/hollajo02.html', '/players/h/holliro01.html', '/players/h/holmeri01.html', '/players/h/hoodro01.html', '/players/h/hoodro01.html', '/players/h/hoodro01.html', '/players/h/horfoal01.html', '/players/h/houseda01.html', '/players/h/howardw01.html', '/players/h/huertke01.html', '/players/h/humphis01.html', '/players/h/hunterj01.html', '/players/h/hutchch01.html', '/players/i/ibakase01.html', '/players/i/iguodan01.html', '/players/i/ilyaser01.html', '/players/i/inglejo01.html', '/players/i/ingraan01.html', '/players/i/ingrabr01.html', '/players/i/irvinky01.html', '/players/i/isaacjo01.html', '/players/i/iwundwe01.html', '/players/j/jacksde01.html', '/players/j/jacksfr01.html', '/players/j/jacksja02.html', '/players/j/jacksjo02.html', '/players/j/jacksju01.html', '/players/j/jacksju01.html', '/players/j/jacksju01.html', '/players/j/jacksre01.html', '/players/j/jamesle01.html', '/players/j/jeffeam01.html', '/players/j/jenkijo01.html', '/players/j/jenkijo01.html', '/players/j/jenkijo01.html', '/players/j/jerebjo01.html', '/players/j/johnsal02.html', '/players/j/johnsam01.html', '/players/j/johnsbj01.html', '/players/j/johnsbj01.html', '/players/j/johnsbj01.html', '/players/j/johnsja01.html', '/players/j/johnsst04.html', '/players/j/johnsst04.html', '/players/j/johnsst04.html', '/players/j/johnsty01.html', '/players/j/johnsty01.html', '/players/j/johnsty01.html', '/players/j/johnswe01.html', '/players/j/johnswe01.html', '/players/j/johnswe01.html', '/players/j/jokicni01.html', '/players/j/jonesda03.html', '/players/j/jonesde02.html', '/players/j/jonesja04.html', '/players/j/jonesje01.html', '/players/j/joneste01.html', '/players/j/jonesty01.html', '/players/j/jordade01.html', '/players/j/jordade01.html', '/players/j/jordade01.html', '/players/j/josepco01.html', '/players/k/kaminfr01.html', '/players/k/kanteen01.html', '/players/k/kanteen01.html', '/players/k/kanteen01.html', '/players/k/kennalu01.html', '/players/k/kiddgmi01.html', '/players/k/kingge03.html', '/players/k/klebima01.html', '/players/k/knighbr03.html', '/players/k/knighbr03.html', '/players/k/knighbr03.html', '/players/k/knoxke01.html', '/players/k/korkmfu01.html', '/players/k/kornelu01.html', '/players/k/korveky01.html', '/players/k/korveky01.html', '/players/k/korveky01.html', '/players/k/koufoko01.html', '/players/k/kurucro01.html', '/players/k/kuzmaky01.html', '/players/l/labissk01.html', '/players/l/labissk01.html', '/players/l/labissk01.html', '/players/l/lambje01.html', '/players/l/lavinza01.html', '/players/l/laymaja01.html', '/players/l/leaftj01.html', '/players/l/leeco01.html', '/players/l/leeco01.html', '/players/l/leeco01.html', '/players/l/leeda03.html', '/players/l/lemonwa01.html', '/players/l/lenal01.html', '/players/l/leonaka01.html', '/players/l/leoname01.html', '/players/l/leuerjo01.html', '/players/l/leverca01.html', '/players/l/lillada01.html', '/players/l/linje01.html', '/players/l/linje01.html', '/players/l/linje01.html', '/players/l/livinsh01.html', '/players/l/loftoza01.html', '/players/l/looneke01.html', '/players/l/lopezbr01.html', '/players/l/lopezro01.html', '/players/l/loveke01.html', '/players/l/lowryky01.html', '/players/l/loydjo01.html', '/players/l/lucaska01.html', '/players/l/luwawti01.html', '/players/l/luwawti01.html', '/players/l/luwawti01.html', '/players/l/lydonty01.html', '/players/l/lylestr01.html', '/players/m/machasc01.html', '/players/m/macksh01.html', '/players/m/macksh01.html', '/players/m/macksh01.html', '/players/m/maconda01.html', '/players/m/macurjp01.html', '/players/m/mahinia01.html', '/players/m/makerth01.html', '/players/m/makerth01.html', '/players/m/makerth01.html', '/players/m/marjabo01.html', '/players/m/marjabo01.html', '/players/m/marjabo01.html', '/players/m/markkla01.html', '/players/m/martija01.html', '/players/m/masonfr01.html', '/players/m/matenya01.html', '/players/m/matthwe02.html', '/players/m/matthwe02.html', '/players/m/matthwe02.html', '/players/m/matthwe02.html', '/players/m/mbahalu01.html', '/players/m/mccalta01.html', '/players/m/mccawpa01.html', '/players/m/mccawpa01.html', '/players/m/mccawpa01.html', '/players/m/mccolcj01.html', '/players/m/mccontj01.html', '/players/m/mcderdo01.html', '/players/m/mcgeeja01.html', '/players/m/mcgruro01.html', '/players/m/mckinal01.html', '/players/m/mclembe01.html', '/players/m/mcraejo01.html', '/players/m/meeksjo01.html', '/players/m/mejrisa01.html', '/players/m/meltode01.html', '/players/m/metuch01.html', '/players/m/middlkh01.html', '/players/m/milescj01.html', '/players/m/milescj01.html', '/players/m/milescj01.html', '/players/m/milleda01.html', '/players/m/millema01.html', '/players/m/millspa02.html', '/players/m/millspa01.html', '/players/m/miltosh01.html', '/players/m/mirotni01.html', '/players/m/mirotni01.html', '/players/m/mirotni01.html', '/players/m/mitchdo01.html', '/players/m/mitrona01.html', '/players/m/monkma01.html', '/players/m/monrogr01.html', '/players/m/monrogr01.html', '/players/m/monrogr01.html', '/players/m/monrogr01.html', '/players/m/mooreet01.html', '/players/m/moreler01.html', '/players/m/moreler01.html', '/players/m/moreler01.html', '/players/m/morrija01.html', '/players/m/morrima03.html', '/players/m/morrima02.html', '/players/m/morrima02.html', '/players/m/morrima02.html', '/players/m/morrimo01.html', '/players/m/motiedo01.html', '/players/m/motlejo01.html', '/players/m/mudiaem01.html', '/players/m/murraja01.html', '/players/m/musadz01.html', '/players/m/muscami01.html', '/players/m/muscami01.html', '/players/m/muscami01.html', '/players/m/mykhasv01.html', '/players/m/mykhasv01.html', '/players/m/mykhasv01.html', '/players/n/naderab01.html', '/players/n/nancela02.html', '/players/n/napiesh01.html', '/players/n/netora01.html', '/players/n/niangge01.html', '/players/n/noahjo01.html', '/players/n/noelne01.html', '/players/n/nowitdi01.html', '/players/n/ntilila01.html', '/players/n/nunnaja01.html', '/players/n/nunnaja01.html', '/players/n/nunnaja01.html', '/players/n/nurkiju01.html', '/players/n/nwabada01.html', '/players/o/onealro01.html', '/players/o/oquinky01.html', '/players/o/ojelese01.html', '/players/o/okafoja01.html', '/players/o/okoboel01.html', '/players/o/okogijo01.html', '/players/o/oladivi01.html', '/players/o/olynyke01.html', '/players/o/osmande01.html', '/players/o/oubreke01.html', '/players/o/oubreke01.html', '/players/o/oubreke01.html', '/players/p/pachuza01.html', '/players/p/parkeja01.html', '/players/p/parkeja01.html', '/players/p/parkeja01.html', '/players/p/parketo01.html', '/players/p/parsoch01.html', '/players/p/pattepa01.html', '/players/p/pattoju01.html', '/players/p/paulch01.html', '/players/p/payneca01.html', '/players/p/payneca01.html', '/players/p/payneca01.html', '/players/p/paytoel01.html', '/players/p/paytoga02.html', '/players/p/pinsoth01.html', '/players/p/plumlma01.html', '/players/p/plumlmi01.html', '/players/p/poeltja01.html', '/players/p/pondequ01.html', '/players/p/porteot01.html', '/players/p/porteot01.html', '/players/p/porteot01.html', '/players/p/portibo01.html', '/players/p/portibo01.html', '/players/p/portibo01.html', '/players/p/poweldw01.html', '/players/p/powelno01.html', '/players/p/poythal01.html', '/players/q/qizh01.html', '/players/r/rabbiv01.html', '/players/r/randlch01.html', '/players/r/randlju01.html', '/players/r/redicjj01.html', '/players/r/reedda01.html', '/players/r/reynoca01.html', '/players/r/richajo01.html', '/players/r/richama01.html', '/players/r/riverau01.html', '/players/r/riverau01.html', '/players/r/riverau01.html', '/players/r/robinde01.html', '/players/r/robindu01.html', '/players/r/robingl02.html', '/players/r/robinje01.html', '/players/r/robinmi01.html', '/players/r/rondora01.html', '/players/r/rosede01.html', '/players/r/rosste01.html', '/players/r/roziete01.html', '/players/r/rubiori01.html', '/players/r/russeda01.html', '/players/s/sabondo01.html', '/players/s/sampsbr01.html', '/players/s/sampsja02.html', '/players/s/saricda01.html', '/players/s/saricda01.html', '/players/s/saricda01.html', '/players/s/satorto01.html', '/players/s/schrode01.html', '/players/s/scottmi01.html', '/players/s/scottmi01.html', '/players/s/scottmi01.html', '/players/s/sefolth01.html', '/players/s/seldewa01.html', '/players/s/seldewa01.html', '/players/s/seldewa01.html', '/players/s/sextoco01.html', '/players/s/shamela01.html', '/players/s/shamela01.html', '/players/s/shamela01.html', '/players/s/shumpim01.html', '/players/s/shumpim01.html', '/players/s/shumpim01.html', '/players/s/siakapa01.html', '/players/s/siberjo01.html', '/players/s/simmobe01.html', '/players/s/simmojo02.html', '/players/s/simmojo02.html', '/players/s/simmojo02.html', '/players/s/simmoko01.html', '/players/s/simonan01.html', '/players/s/smartma01.html', '/players/s/smithde03.html', '/players/s/smithde03.html', '/players/s/smithde03.html', '/players/s/smithis01.html', '/players/s/smithjr01.html', '/players/s/smithja02.html', '/players/s/smithja02.html', '/players/s/smithja02.html', '/players/s/smithja02.html', '/players/s/smithzh01.html', '/players/s/snellto01.html', '/players/s/spaldra01.html', '/players/s/spaldra01.html', '/players/s/spaldra01.html', '/players/s/spellom01.html', '/players/s/stausni01.html', '/players/s/stausni01.html', '/players/s/stausni01.html', '/players/s/stephdj01.html', '/players/s/stephla01.html', '/players/s/sumneed01.html', '/players/s/swanica01.html', '/players/s/swanica01.html', '/players/s/swanica01.html', '/players/t/tatumja01.html', '/players/t/teaguje01.html', '/players/t/templga01.html', '/players/t/templga01.html', '/players/t/templga01.html', '/players/t/teodomi01.html', '/players/t/terreja01.html', '/players/t/terryem01.html', '/players/t/terryem01.html', '/players/t/terryem01.html', '/players/t/theisda01.html', '/players/t/thomais02.html', '/players/t/thomakh01.html', '/players/t/thomala01.html', '/players/t/thompkl01.html', '/players/t/thomptr01.html', '/players/t/thornsi01.html', '/players/t/tollian01.html', '/players/t/townska01.html', '/players/t/trentga02.html', '/players/t/trieral01.html', '/players/t/tuckepj01.html', '/players/t/turneev01.html', '/players/t/turnemy01.html', '/players/u/udohek01.html', '/players/u/ulisty01.html', '/players/v/valanjo01.html', '/players/v/valanjo01.html', '/players/v/valanjo01.html', '/players/v/vandeja01.html', '/players/v/vanvlfr01.html', '/players/v/vonleno01.html', '/players/v/vucevni01.html', '/players/w/wadedw01.html', '/players/w/wagnemo01.html', '/players/w/waitedi01.html', '/players/w/walkeke02.html', '/players/w/walkelo01.html', '/players/w/walljo01.html', '/players/w/wallaty01.html', '/players/p/princta02.html', '/players/w/wanambr01.html', '/players/w/warretj01.html', '/players/w/washbju01.html', '/players/w/watanyu01.html', '/players/w/welshth01.html', '/players/w/westbru01.html', '/players/w/whitede01.html', '/players/w/whiteok01.html', '/players/w/whiteha01.html', '/players/w/wiggian01.html', '/players/w/willial03.html', '/players/w/willicj01.html', '/players/w/willijo04.html', '/players/w/willike04.html', '/players/w/willilo02.html', '/players/w/willima02.html', '/players/w/williro04.html', '/players/w/willitr02.html', '/players/w/wilsodj01.html', '/players/w/winslju01.html', '/players/w/woodch01.html', '/players/w/woodch01.html', '/players/w/woodch01.html', '/players/w/wrighde01.html', '/players/w/wrighde01.html', '/players/w/wrighde01.html', '/players/y/yabusgu01.html', '/players/y/youngni01.html', '/players/y/youngth01.html', '/players/y/youngtr01.html', '/players/z/zelleco01.html', '/players/z/zellety01.html', '/players/z/zellety01.html', '/players/z/zellety01.html', '/players/z/zizican01.html', '/players/z/zubaciv01.html', '/players/z/zubaciv01.html', '/players/z/zubaciv01.html']
I would use a set comprehension to remove duplicates and also I think nth-of-type to select the appropriate column reads more cleanly. Using bs4 4.7.1
import requests
from bs4 import BeautifulSoup as bs
soup = bs(requests.get('https://www.basketball-reference.com/leagues/NBA_2019_per_game.html').text, 'html.parser')
links = {i['href'] for i in soup.select('#per_game_stats td:nth-of-type(1) a')}
print(links)
You could also use the following css selector:
[csk] > a
I am trying to write a python script that goes onto the website https://www.premierleague.com/players, takes a list of football player names from a spreadsheet I have (400+ footballer names), and inside a loop, iteratively searches for the link to each football player's page. For example : https://www.premierleague.com/players/4040/Benik-Afobe/overview.
The final bit of the script is commented out as I have finalised that yet, but for context of what I'm eventually going to get to: it will take this list of urls that I will have obtained, and iteratively search for each players link to the player image, and append it to a list.
I managed to get it to work for an individual player (Benik Afobe), but since adding the 'players_list' and trying a loop, I get the following error:
Traceback (most recent call last):
File "C:/Users/Liam/Documents/GitHub/Football_Scraping/fantast_pl_images.py", line 33, in <module>
player_link = soup.find('a', href=re.compile('%s'))['href'] %player
TypeError: 'NoneType' object is not subscriptable
Does anyone know what I'm doing wrong and how to get my loop working?
The Repo of my project can be found here: https://github.com/leej11/Football_Scraping
# Import the Libraries that I need
import urllib3
import certifi
from bs4 import BeautifulSoup
import re
import pandas as pd
# Specify the URL
url = 'https://www.premierleague.com/players'
http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
response = http.request('GET', url, headers={'User-Agent': 'Mozilla/5.0'})
#Parse the html using beautiful soup and store in variable 'soup'
soup = BeautifulSoup(response.data, "html.parser")
#Importing the list of players I want to scrape the image of
players_list = pd.read_csv('epl_players_anki_clean.csv')
#Test that it's pulling all of the players names correctly
print(players_list.iloc[:,0])
print (type(players_list))
#Convert the pandas dataframe to a list of strings, with each item being the string of a player name
list_of_players = players_list['name'].values.tolist()
print(list_of_players)
#Setup an empty list to append the player links to
player_link_list = []
#Loop over the list of player names, and search for the player url and append it to the player_link_list
for player in players_list:
player_link = soup.find('a', href=re.compile('%s'))['href'] %player
print(player_link)
player_url = 'https://www.premierleague.com' + '%s' %player_link
print(player_url)
player_link_list.append(player_url)
##### The final step
##### To be worked on in a bit, basically take the list of links and loop over it pulling out the player image links and appending them to a list
#####
# url2 = player_url
# http2 = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
# response2 = http2.request('GET', url2, headers={'User-Agent': 'Mozilla/5.0'})
# soup2 = BeautifulSoup(response2.data, "html.parser")
# player_img = str(soup2.find("img", {'alt':'Benik Afobe'})['data-player'])
# print(player_img)
#
# photo_link = 'http://platform-static-files.s3.amazonaws.com/premierleague/photos/players/250x250/' + '%s' %player_img + '.png'
# print(photo_link)
It appears that the Premier League's player listing is dynamic, meaning that a browser script is loading additional players as the user scrolls down. Thus, using requests or urllib to find all the players will not work. Therefore, you will have to use a browser manipulation tool called selenium:
Install:
pip install selenium:
Then, install the proper binding for the webbrowser you are using:
http://selenium-python.readthedocs.io/installation.html#drivers
import re
import selenium
import time
import csv
driver = selenium.webdriver.Chrome('/path/to/driver')#substitute Chrome with browser you are using
driver.get('https://www.premierleague.com/players')
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(0.5)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
time.sleep(10)
players = re.findall('www\.premierleague\.com/players/(.*?)/(.*?)/overview', driver.page_source)
csv_filedata = list(csv.reader(open('epl_players_anki_clean.csv')))
player_dict = {re.sub('-', ' ', b):(a, b) for a, b in players}
new_rows = [[csv_filedata[0]]+['url']]+[a+['https://www.premierleague.com/players/{}/{}/overview'.format(*player_dict[a[0]])] for a in csv_filedata]
with open('players.csv', 'a') as f:
write = csv.writer(f)
write.writerows(new_rows)
player_dict stores the following (truncated data):
Output:
{u'Asmir Begovic': [u'2537', u'Asmir-Begovic'], u'Ragnar Klavan': [u'15608', u'Ragnar-Klavan'], u'Eddie Nketiah': [u'14451', u'Eddie-Nketiah'], u'Mohamed Salah': [u'5178', u'Mohamed-Salah'], u'Jos\xe9 Holebas': [u'5713', u'Jos\xe9-Holebas'], u'Christian Eriksen': [u'4845', u'Christian-Eriksen'], u'Kurt Zouma': [u'5175', u'Kurt-Zouma'], u'Gareth Barry': [u'1308', u'Gareth-Barry'], u'Diego Costa': [u'4941', u'Diego-Costa'], u'Sam McQueen': [u'9649', u'Sam-McQueen'], u'Roque Mesa': [u'22575', u'Roque-Mesa'], u'Siem de Jong': [u'4885', u'Siem-de-Jong'], u'Lazar Markovic': [u'5078', u'Lazar-Markovic'], u'Adam Federici': [u'3182', u'Adam-Federici'], u'Dean Marney': [u'2359', u'Dean-Marney'], u'Nathan Broadhead': [u'14636', u'Nathan-Broadhead'], u'Alex Pritchard': [u'4433', u'Alex-Pritchard'], u'Matthew Pennington': [u'9895', u'Matthew-Pennington'], u'Tomas Kalas': [u'4101', u'Tomas-Kalas'], u'Nathan Ak\xe9': [u'4499', u'Nathan-Ak\xe9'], u'Mathias Normann': [u'23556', u'Mathias-Normann'], u'Grzegorz Krychowiak': [u'12735', u'Grzegorz-Krychowiak'], u'Wojciech Szczesny': [u'3543', u'Wojciech-Szczesny'], u'Charlie Adam': [u'4081', u'Charlie-Adam'], u'Marko Grujic': [u'13985', u'Marko-Grujic'], u'Harry Maguire': [u'9566', u'Harry-Maguire'], u'Isaiah Brown': [u'4674', u'Isaiah-Brown'], u'Matz Sels': [u'16723', u'Matz-Sels'], u'Leighton Baines': [u'3030', u'Leighton-Baines'], u'Marouane Fellaini': [u'3604', u'Marouane-Fellaini'], u'Jairo Riedewald': [u'4878', u'Jairo-Riedewald'], u'Glenn Murray': [u'4772', u'Glenn-Murray'], u'Tom Cadman': [u'14547', u'Tom-Cadman'], u'Ryan Shawcross': [u'3158', u'Ryan-Shawcross'], u"N'Golo Kant\xe9": [u'13492', u"N'Golo-Kant\xe9"], u'Aaron Ramsey': [u'3548', u'Aaron-Ramsey'], u'Stephen Kingsley': [u'10517', u'Stephen-Kingsley'], u'Eliaquim Mangala': [u'5334', u'Eliaquim-Mangala'], u'Josh Tymon': [u'13477', u'Josh-Tymon'], u'Mohamed Diam\xe9': [u'3982', u'Mohamed-Diam\xe9'], u'Sofiane Boufal': [u'12584', u'Sofiane-Boufal'], u'Nya Kirby': [u'15134', u'Nya-Kirby'], u'Max Melbourne': [u'15160', u'Max-Melbourne'], u'Marcin Bulka': [u'23695', u'Marcin-Bulka'], u'Rub\xe9n Sobrino': [u'16608', u'Rub\xe9n-Sobrino'], u'Tareiq Holmes Dennis': [u'8340', u'Tareiq-Holmes-Dennis'], u'Martin Cranie': [u'2559', u'Martin-Cranie'], u'Connor Mahoney': [u'7985', u'Connor-Mahoney'], u'Jamaal Lascelles': [u'9257', u'Jamaal-Lascelles'], u'Phil Foden': [u'14805', u'Phil-Foden'], u'Arijanet Muric': [u'19911', u'Arijanet-Muric'], u'Sadio Man\xe9': [u'6519', u'Sadio-Man\xe9'], u"Aiden O'Neill": [u'20095', u"Aiden-O'Neill"], u'Steve Cook': [u'8045', u'Steve-Cook'], u'Samuel Shashoua': [u'15142', u'Samuel-Shashoua'], u'Kyle Bartley': [u'3312', u'Kyle-Bartley'], u'Bojan': [u'4898', u'Bojan'], u'Jason Puncheon': [u'4084', u'Jason-Puncheon'], u'Damien Delaney': [u'1911', u'Damien-Delaney'], u'Steven Defour': [u'5345', u'Steven-Defour'], u'Christian Walton': [u'8159', u'Christian-Walton'], u'Timothy Fosu Mensah': [u'13561', u'Timothy-Fosu-Mensah'], u'Michael Keane': [u'4333', u'Michael-Keane'], u'Levi Lumeka': [u'14170', u'Levi-Lumeka'], u'Chancel Mbemba': [u'5850', u'Chancel-Mbemba'], u'Brice Dja Dj\xe9dj\xe9': [u'5577', u'Brice-Dja-Dj\xe9dj\xe9'], u'Vurnon Anita': [u'4550', u'Vurnon-Anita'], u'Jefferson Montero': [u'10518', u'Jefferson-Montero'], u'Toby Alderweireld': [u'4916', u'Toby-Alderweireld'], u'Dominic Calvert Lewin': [u'9576', u'Dominic-Calvert-Lewin'], u'Brad Jackson': [u'13246', u'Brad-Jackson'], u'James McArthur': [u'4224', u'James-McArthur'], u'Mat Ryan': [u'12192', u'Mat-Ryan'], u'Bartosz Kapustka': [u'19679', u'Bartosz-Kapustka'], u'Robert Snodgrass': [u'4558', u'Robert-Snodgrass'], u'Jonathan Leko': [u'13866', u'Jonathan-Leko'], u'Harry Arter': [u'8050', u'Harry-Arter'], u'Connor Goldson': [u'9634', u'Connor-Goldson'], u'Shaun Hobson': [u'21691', u'Shaun-Hobson'], u'Ayoze P\xe9rez': [u'10487', u'Ayoze-P\xe9rez'], u'Marc Pugh': [u'8049', u'Marc-Pugh'], u'Luciano Narsingh': [u'7122', u'Luciano-Narsingh'], u'Michael Folivi': [u'14298', u'Michael-Folivi'], u'Adri\xe1n': [u'4852', u'Adri\xe1n'], u'Mason Holgate': [u'10564', u'Mason-Holgate'], u'Joy Mukena': [u'15118', u'Joy-Mukena'], u"Lewis O'Brien": [u'24353', u"Lewis-O'Brien"], u'Javier Manquillo': [u'4918', u'Javier-Manquillo'], u"Dara O'Shea": [u'15154', u"Dara-O'Shea"], u"Clinton N'Jie": [u'6903', u"Clinton-N'Jie"], u'Yoan Gouffran': [u'4554', u'Yoan-Gouffran'], u'Michael Carrick': [u'1634', u'Michael-Carrick'], u'Moha': [u'13778', u'Moha'], u'Michy Batshuayi': [u'7450', u'Michy-Batshuayi'], u'Nathaniel Chalobah': [u'4105', u'Nathaniel-Chalobah'], u'Ryan Inniss': [u'4760', u'Ryan-Inniss'], u'Etienne Capoue': [u'4843', u'Etienne-Capoue'], u'Badou Ndiaye': [u'20538', u'Badou-Ndiaye'], u'Alexandre Lacazette': [u'6899', u'Alexandre-Lacazette'], u'Charlie Rowan': [u'14285', u'Charlie-Rowan'], u'Nathan Ferguson': [u'23976', u'Nathan-Ferguson'], u'Anthony Georgiou': [u'15146', u'Anthony-Georgiou'], u'Dujon Sterling': [u'14572', u'Dujon-Sterling'], u'Axel Tuanzebe': [u'13559', u'Axel-Tuanzebe'], u'Emre Can': [u'5001', u'Emre-Can'], u'Sam Surridge': [u'13195', u'Sam-Surridge'], u'Ryan Kent': [u'13509', u'Ryan-Kent'], u'Marc Albrighton': [u'3564', u'Marc-Albrighton'], u'Joe Williams': [u'10454', u'Joe-Williams'], u'Tom Heaton': [u'2933', u'Tom-Heaton'], u'Danny Rose': [u'3507', u'Danny-Rose'], u'Nathan Redmond': [u'3811', u'Nathan-Redmond'], u'Chicharito': [u'4161', u'Chicharito'], u'Dean Whitehead': [u'2980', u'Dean-Whitehead'], u'M.J. Williams': [u'10464', u'M.J.-Williams'], u'Harry Winks': [u'7488', u'Harry-Winks'], u'Josh Sims': [u'15374', u'Josh-Sims'], u'Charlie Gilmour': [u'14453', u'Charlie-Gilmour'], u'Aaron Wan Bissaka': [u'14164', u'Aaron-Wan-Bissaka'], u'Marc Muniesa': [u'4822', u'Marc-Muniesa'], u'Beni Baningime': [u'14623', u'Beni-Baningime'], u'Demarai Gray': [u'7946', u'Demarai-Gray'], u'Junior Stanislas': [u'3766', u'Junior-Stanislas'], u'Liam Rosenior': [u'2464', u'Liam-Rosenior'], u'Nathaniel Clyne': [u'4604', u'Nathaniel-Clyne'], u'Kamil Grabara': [u'19909', u'Kamil-Grabara'], u'Anthony Martial': [u'11272', u'Anthony-Martial'], u'Ben Foster': [u'2932', u'Ben-Foster'], u'Laurent Depoitre': [u'16747', u'Laurent-Depoitre'], u'Mike van der Hoorn': [u'4877', u'Mike-van-der-Hoorn'], u'Didier Ndong': [u'20708', u'Didier-Ndong'], u'Jordon Mutch': [u'3333', u'Jordon-Mutch'], u'Harry Kane': [u'3960', u'Harry-Kane'], u'Fernandinho': [u'4804', u'Fernandinho'], u'Riyad Mahrez': [u'8983', u'Riyad-Mahrez'], u'Kleton Perntreou': [u'14144', u'Kleton-Perntreou'], u'Dion Henry': [u'10855', u'Dion-Henry'], u'Kelechi Iheanacho': [u'13554', u'Kelechi-Iheanacho'], u'Salom\xf3n Rond\xf3n': [u'6030', u'Salom\xf3n-Rond\xf3n'], u'Ryan Allsop': [u'3732', u'Ryan-Allsop'], u'Erik Pieters': [u'4821', u'Erik-Pieters'], u'Willy Caballero': [u'10466', u'Willy-Caballero'], u'Claudio Yacob': [u'4673', u'Claudio-Yacob'], u'Craig Dawson': [u'4198', u'Craig-Dawson'], u'Jayson Molumby': [u'15293', u'Jayson-Molumby'], u'Lucas Leiva': [u'3137', u'Lucas-Leiva'], u'Martin Dubravka': [u'6451', u'Martin-Dubravka'], u'Bruno': [u'8162', u'Bruno'], u'Sam Johnstone': [u'4331', u'Sam-Johnstone'], u'Jes\xfas G\xe1mez': [u'11070', u'Jes\xfas-G\xe1mez'], u'Tomer Hemed': [u'13234', u'Tomer-Hemed'], u'Victor Moses': [u'3983', u'Victor-Moses'], u'Vincent Janssen': [u'15481', u'Vincent-Janssen'], u'Lo\xefc Remy': [u'4572', u'Lo\xefc-Remy'], u'Craig Cathcart': [u'3160', u'Craig-Cathcart'], u'Leroy Fer': [u'4810', u'Leroy-Fer'], u"Kieran O'Hara": [u'13584', u"Kieran-O'Hara"], u'Ola Aina': [u'10439', u'Ola-Aina'], u'Winston Reid': [u'4209', u'Winston-Reid'], u'Jose Baxter': [u'3608', u'Jose-Baxter'], u'Michael Obafemi': [u'21532', u'Michael-Obafemi'], u'Bruno Martins Indi': [u'11177', u'Bruno-Martins-Indi'], u'Laurent Koscielny': [u'4030', u'Laurent-Koscielny'], u'Borja Bast\xf3n': [u'16622', u'Borja-Bast\xf3n'], u'Daryl Janmaat': [u'10480', u'Daryl-Janmaat'], u'Freddy Woodman': [u'10479', u'Freddy-Woodman'], u'Jordy Hiwula Mayifuila': [u'10949', u'Jordy-Hiwula-Mayifuila'], u'Raphael Spiegel': [u'4679', u'Raphael-Spiegel'], u'Anthony Knockaert': [u'8982', u'Anthony-Knockaert'], u'Harry Lewis': [u'14982', u'Harry-Lewis'], u'Henrikh Mkhitaryan': [u'5102', u'Henrikh-Mkhitaryan'], u'Santiago Cazorla': [u'4477', u'Santiago-Cazorla'], u'Sean Scannell': [u'8887', u'Sean-Scannell'], u'Christian Atsu': [u'4859', u'Christian-Atsu'], u'Pascal Gro\xdf': [u'22542', u'Pascal-Gro\xdf'], u'Charlie Austin': [u'9468', u'Charlie-Austin'], u'Sam Byram': [u'8945', u'Sam-Byram'], u'Daniel Sturridge': [u'3154', u'Daniel-Sturridge'], u'Ga\xebtan Bong': [u'5721', u'Ga\xebtan-Bong'], u'Martin Kelly': [u'3644', u'Martin-Kelly'], u'Jack Payne': [u'9664', u'Jack-Payne'], u'Michel Vorm': [u'4398', u'Michel-Vorm'], u'Oriol Romeu': [u'4286', u'Oriol-Romeu'], u'Philip Billing': [u'8882', u'Philip-Billing'], u'Matthew Lowton': [u'4487', u'Matthew-Lowton'], u'Wayne Hennessey': [u'2569', u'Wayne-Hennessey'], u'Geoff Cameron': [u'4636', u'Geoff-Cameron'], u'Tammy Abraham': [u'13286', u'Tammy-Abraham'], u'Elvis Manu': [u'12374', u'Elvis-Manu'], u'Marvin Zeegelaar': [u'10123', u'Marvin-Zeegelaar'], u'Jordy Clasie': [u'12365', u'Jordy-Clasie'], u'Wayne Routledge': [u'2681', u'Wayne-Routledge'], u'Tom Anderson': [u'8234', u'Tom-Anderson'], u'Stephen Duke McKenna': [u'23738', u'Stephen-Duke-McKenna'], u'Harry Charsley': [u'14632', u'Harry-Charsley'], u'Erik Lamela': [u'4842', u'Erik-Lamela'], u'Elias Kachunga': [u'19611', u'Elias-Kachunga'], u'Molla Wagu\xe9': [u'21730', u'Molla-Wagu\xe9'], u'Ilkay G\xfcndogan': [u'5101', u'Ilkay-G\xfcndogan'], u'Ashley Williams': [u'4403', u'Ashley-Williams'], u'Lewis Grabban': [u'8055', u'Lewis-Grabban'], u'Seamus Coleman': [u'3600', u'Seamus-Coleman'], u'Jason Denayer': [u'11002', u'Jason-Denayer'], u'Jack Wilshere': [u'3547', u'Jack-Wilshere'], u'Calum Chambers': [u'4620', u'Calum-Chambers'], u'Samir Nasri': [u'3546', u'Samir-Nasri'], u'Alexis S\xe1nchez': [u'4973', u'Alexis-S\xe1nchez'], u'Kyle Walker': [u'3955', u'Kyle-Walker'], u'Martin Olsson': [u'2867', u'Martin-Olsson'], u'Modou Barrow': [u'10520', u'Modou-Barrow'], u'Robbie Brady': [u'4158', u'Robbie-Brady'], u'Tom Davies': [u'13389', u'Tom-Davies'], u'Fraser Forster': [u'3170', u'Fraser-Forster'], u'Francis Coquelin': [u'3549', u'Francis-Coquelin'], u'Matt Targett': [u'4815', u'Matt-Targett'], u'Davy Klaassen': [u'4886', u'Davy-Klaassen'], u"Stefan O'Connor": [u'10425', u"Stefan-O'Connor"], u'Fraser Hornby': [u'23744', u'Fraser-Hornby'], u'Tim Krul': [u'3169', u'Tim-Krul'], u'Ryan Hill': [u'21858', u'Ryan-Hill'], u'J\xfcrgen Locadia': [u'7124', u'J\xfcrgen-Locadia'], u'Ki Sung yueng': [u'4656', u'Ki-Sung-yueng'], u'Leon Britton': [u'2152', u'Leon-Britton'], u'Mesut \xd6zil': [u'4714', u'Mesut-\xd6zil'], u'Alex Denny': [u'14643', u'Alex-Denny'], u'Nemanja Matic': [u'3861', u'Nemanja-Matic'], u'Ryan Fraser': [u'8052', u'Ryan-Fraser'], u'Julian Speroni': [u'2664', u'Julian-Speroni'], u'Joel Campbell': [u'4254', u'Joel-Campbell'], u'Robert Elliot': [u'2214', u'Robert-Elliot'], u'Tosin Adarabioyo': [u'13549', u'Tosin-Adarabioyo'], u'Jack Colback': [u'3713', u'Jack-Colback'], u'Soufyan Ahannach': [u'24695', u'Soufyan-Ahannach'], u'Aaron Connolly': [u'21653', u'Aaron-Connolly'], u'Yasin Ben El Mhanni': [u'20879', u'Yasin-Ben-El-Mhanni'], u'Kazenga Lua Lua': [u'3173', u'Kazenga-Lua-Lua'], u'Ben Chilwell': [u'13491', u'Ben-Chilwell'], u'Aaron Ramsdale': [u'13703', u'Aaron-Ramsdale']}
I am using the code below to try an extract the data at the table in this URL. However, I get the following error message:
Error: `AttributeError: 'NoneType' object has no attribute 'find'`in
the line `data = iter(soup.find("table", {"class":
"tablestats"}).find("th", {"class": "header"}).find_all_next("tr"))`
My code is as follows:
from bs4 import BeautifulSoup
import requests
r = requests.get(
"http://www.federalreserve.gov/econresdata/researchdata/feds200628_1.html")
soup = BeautifulSoup(r.content)
data = iter(soup.find("table", {"class": "tablestats"}).find("th", {"class": "header"}).find_all_next("tr"))
headers = (next(data).text, next(data).text)
table_items = [(a.text, b.text) for ele in data for a, b in [ele.find_all("td")]]
for a, b in table_items:
print(u"Date={}, Maturity={}".format(a, b if b.strip() else "null"))
Thank You
from bs4 import BeautifulSoup
import requests
r = requests.get(
"http://www.federalreserve.gov/econresdata/researchdata/feds200628_1.html")
soup = BeautifulSoup(r.content)
# column headers
h = data.find_all("th", scope="col")
# get all the tr tags after the headers
final = [[t.th.text] + [ele.text for ele in t.find_all("td")] for t in h[-1].find_all_next("tr")]
headers = [th.text for th in h]
The final out list is all the rows in individual lists:
[['2015-06-05', '4.82039691', '-4.66420959', '-4.18904598',
'-3.94541434', '1.1477', '2.9361', '3.3588', '0.6943', '1.5881',
'2.3034', '2.7677', '3.0363', '3.1801', '3.2537', '3.2930', '3.3190',
'3.3431', '3.3707', '3.4038', '3.4428', '3.4871', '3.5357', '3.5876',
'3.6419', '3.6975', '3.7538', '3.8100', '3.8656', '3.9202', '3.9734',
'4.0250', '4.0748', '4.1225', '4.1682', '4.2117', '4.2530', '4.2921',
'0.3489', '0.7464', '1.1502', '1.4949', '1.7700', '1.9841', '2.1500',
'2.2800', '2.3837', '2.4685', '2.5396', '2.6006', '2.6544', '2.7027',
'2.7469', '2.7878', '2.8260', '2.8621', '2.8964', '2.9291', '2.9603',
'2.9901', '3.0187', '3.0461', '3.0724', '3.0976', '3.1217', '3.1448',
'3.1669', '3.1881', '0.3487', '0.7469', '1.1536', '1.5039', '1.7862',
'2.0078', '2.1811', '2.3179', '2.4277', '2.5181', '2.5943', '2.6603',
'2.7190', '2.7722', '2.8215', '2.8677', '2.9117', '2.9538', '2.9944',
'3.0338', '3.0721', '3.1094', '3.1458', '3.1814', '3.2161', '3.2501',
'3.2832', '3.3156', '3.3472', '3.3781', '1.40431658', '9.48795888'],
['2015-06-04', '4.64953424', '-4.52780982', '-3.98051369',
......................................
The headers:
['BETA0', 'BETA1', 'BETA2', 'BETA3', 'SVEN1F01', 'SVEN1F04', 'SVEN1F09', 'SVENF01', 'SVENF02', 'SVENF03', 'SVENF04', 'SVENF05', 'SVENF06', 'SVENF07', 'SVENF08', 'SVENF09', 'SVENF10', 'SVENF11', 'SVENF12', 'SVENF13', 'SVENF14', 'SVENF15', 'SVENF16', 'SVENF17', 'SVENF18', 'SVENF19', 'SVENF20', 'SVENF21', 'SVENF22', 'SVENF23', 'SVENF24', 'SVENF25', 'SVENF26', 'SVENF27', 'SVENF28', 'SVENF29', 'SVENF30', 'SVENPY01', 'SVENPY02', 'SVENPY03', 'SVENPY04', 'SVENPY05', 'SVENPY06', 'SVENPY07', 'SVENPY08', 'SVENPY09', 'SVENPY10', 'SVENPY11', 'SVENPY12', 'SVENPY13', 'SVENPY14', 'SVENPY15', 'SVENPY16', 'SVENPY17', 'SVENPY18', 'SVENPY19', 'SVENPY20', 'SVENPY21', 'SVENPY22', 'SVENPY23', 'SVENPY24', 'SVENPY25', 'SVENPY26', 'SVENPY27', 'SVENPY28', 'SVENPY29', 'SVENPY30', 'SVENY01', 'SVENY02', 'SVENY03', 'SVENY04', 'SVENY05', 'SVENY06', 'SVENY07', 'SVENY08', 'SVENY09', 'SVENY10', 'SVENY11', 'SVENY12', 'SVENY13', 'SVENY14', 'SVENY15', 'SVENY16', 'SVENY17', 'SVENY18', 'SVENY19', 'SVENY20', 'SVENY21', 'SVENY22', 'SVENY23', 'SVENY24', 'SVENY25', 'SVENY26', 'SVENY27', 'SVENY28', 'SVENY29', 'SVENY30', 'TAU1', 'TAU2']
There are a lot of issues in your code.
There is no table with class 'tablestats'.
There are no 'th' fields with class 'header'.
Following line-
table_items = [(a.text, b.text) for ele in data for a, b in [ele.find_all("td")]]
doesnt return just 2 values, so cant assign to a, b